Create random password with no vowels

1. Senior Member
Join Date
Dec 1969
Posts
490

## Create random password with no vowels

Hiya,<BR><BR>I&#039;m creatng passwords on the fly using the following function<BR><BR>Function generatePassword( allowNumbers )<BR> NUMLOWER = 48 &#039; 48 = 0<BR> NUMUPPER = 57 &#039; 57 = 9<BR> LOWERBOUND = 65 &#039; 65 = A<BR> UPPERBOUND = 90 &#039; 90 = Z<BR> LOWERBOUND1 = 97 &#039; 97 = a<BR> UPPERBOUND1 = 122 &#039; 122 = z<BR> PASSWORD_LENGTH = 5<BR><BR> Randomize()<BR><BR> newPassword = ""<BR> count = 0<BR> DO UNTIL count = PASSWORD_LENGTH<BR> If allowNumbers Then<BR> pwd = Int( ( NUMUPPER - NUMLOWER ) * Rnd + NUMLOWER )<BR> Else<BR> If Int( ( 10 - 2 + 1 ) * Rnd + 2 ) &#062; 4 Then<BR> pwd = Int( ( UPPERBOUND - LOWERBOUND + 1 ) * Rnd + LOWERBOUND )<BR> Else<BR> pwd = Int( ( UPPERBOUND1 - LOWERBOUND1 + 1 ) * Rnd + LOWERBOUND1 )<BR> End If<BR> End If<BR><BR> newPassword = newPassword + Chr( pwd )<BR><BR> count = count + 1<BR> Loop<BR><BR> generatePassword = newPassword<BR>End Function<BR><BR>No numbers are in a password if function called like so<BR><BR>strPassword = generatePassword(false)<BR><BR>However, i also want to exclude vowels so that i don&#039;t hand out a password like uC*nT... think you can guess what the * is. Sorry about that (shrug)<BR><BR>If anyone can suggest other letters that might be useful to exclude i.e. lowercase &#039;L&#039; because it&#039;s hard to tell what it actually is in unformatted text...<BR><BR>Thanks in advance and sorry again about the swearing,<BR><BR>Kes<BR><BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: Create random password with no vowels

You could make that loop a little more effective, but to answer your immediate question, just check each letter for a vowel.<BR><BR>Dim Vowels<BR>Vowels = Array("A", "E", "I", "O", "U")<BR><BR>My VBS is very rusty, so here&#039;s the best I can get:<BR><BR>for (i = 0 to ubound(Vowels)<BR>if (UCase(letter) = Vowels(i))<BR> //then get out of here<BR>next

3. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## LOL...funny

i never though of that, i coded a quick function to generate 8 char pwds but never thought of sending out swear words....I wonder if those guys ever got complaints<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## BLECH! Wrong way entirely, I think

&nbsp;<BR>&#060;%<BR>PWD_CHARS = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz0123456 789"<BR><BR>Randomize<BR><BR>Function genPassword( count )<BR> Dim pwd, i, pcnt<BR> pwd = ""<BR> pcnt = Len(PWD_CHARS)<BR><BR> For i = 1 To count<BR> pwd = pwd & Mid( PWD_CHARS, 1 + Int(RND * pcnt), 1 )<BR> Next<BR> genPassword = pwd<BR>End Function<BR>%&#062;<BR><BR>If you don&#039;t want numbers, leave them out of the PWD_CHARS string.<BR><BR>If you want to allow some symbols, stuff them into it.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•