Webmaster Forum

Go Back   Webmaster Forum > Scripting/Programming & Debugging > ASP & VBScript Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

ASP & VBScript Forum Need help from a webmaster with ASP or VBScript, you may ask in this forum?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-24-2007, 07:53 PM
a_lane a_lane is offline
Junior Member
 
Join Date: Aug 2007
Posts: 1
a_lane is an unknown quantity at this point
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq Submit to Spurl
Default Generate a username

For an Active Directory, automated user account creation script I've designed and tested the username is supposed to be inputted when the script is run. The password for the account is generated using a password-generating function that I googled, but my boss has requested that the username should be generated the same way as the password is. Meaning he wants to supply the first and last name of the user, their description, and some other menial data, and when the script tries to create the account it will check the availability for say firstname+lastname as the username and if thats not availabe, it will dynamically generate other possible usernames.

Is there a way in VBScript to generate a string that would be perhaps the first letter in one string+a second string, then if that isn't available as a username it would take the first 2 letters+the second string.

e.g.
user is Joe Brown

create user JoeBrown: error name exists already
create user JBrown: error name exists already
create user JoBrown: success

I could do this simple enough with C# but of course I'm stuck in vbscript.
Any vb wizards out there able to shed some light on my predicament?

Thanks
Reply With Quote

This ad is part of our Revenue Sharing program
  #2 (permalink)  
Old 08-28-2007, 03:15 AM
ALL's Avatar
ALL ALL is offline
Senior Member
 
Join Date: Oct 2006
Location: Sturgis, SD
Posts: 145
ALL is on a distinguished road
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq Submit to Spurl
Default

try something like this:

Code:
Function tryName(firstName, lastName) If(checkUN(firstName+lastName)) Then return firstName+lastName ElseIf(checkUN(Mid(firstName,1,1)+lastName)) Then return Mid(firstName,1,1)+lastName ElseIf(checkUN(Mid(firstName,1,Len(firstName)-1)+lastName)) Then return Mid(firstName,1,Len(firstName)-1)+lastName Else i = 0 Do While True i = i + 1 If(checkUN(firstName+lastName+CStr(i))) Then return firstName+lastName+CStr(i) End If Loop End If End Function Function checkUN(username) 'This would be the function to check if a username exists (needs to return true or false End Function
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:11 AM.


Creative Commons License
Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.0.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30