Jump to content
• Sign Up

# Random Password

## Recommended Posts

Not sure if anything has been posted like this, but found I needed a random password generator, thought I would share this little snippet.

Improvements/comments welcome.

Cleaned up the code and ran Tidy on it.

Dim \$PASSWORD = '', \$MAXLENGTH = 8

For \$MAXLENGTH = 8 To 36 Step 1

\$PASSWORD = Random_Password(\$MAXLENGTH)

MsgBox(4096, 'test', \$PASSWORD)

Next

Exit

Func Random_Password(\$MAXLENGTH)

Dim \$I = 0, \$PASSWORD = '', \$X = 0, \$NUM_IN_PATTERN = 0, \$SPECIAL_CHAR[7]

; create custom pattern

\$SPECIAL_CHAR[0] = '#'

\$SPECIAL_CHAR[1] = '\$'

\$SPECIAL_CHAR[2] = '_'

\$SPECIAL_CHAR[3] = '+'

\$SPECIAL_CHAR[4] = '\$'

\$SPECIAL_CHAR[5] = '-'

\$SPECIAL_CHAR[6] = '+'

;set the pattern to n characters long divisable by 4

;in a random order

Do

\$X = Round(Random(1, 4))

if (\$X == 1) Then

\$PASSWORD = \$PASSWORD & Chr(Random(Asc("a"), Asc("z") + 1))

elseif (\$X == 2) Then

\$PASSWORD = \$PASSWORD & Chr(Random(Asc("A"), Asc("Z") + 1))

elseif (\$X == 3) Then

\$PASSWORD = \$PASSWORD & Round(Random(0, 9))

elseif (\$X == 4) Then

\$PASSWORD = \$PASSWORD & \$SPECIAL_CHAR[Round(Random(0, 3)) ]

EndIf

\$NUM_IN_PATTERN = \$NUM_IN_PATTERN + 1

Until \$NUM_IN_PATTERN == \$MAXLENGTH

Return \$PASSWORD

EndFunc ;==>Random_Password

Edited by gafrost

Don't argue with an idiot; people watching may not be able to tell the difference.

#### Share this post

##### Share on other sites

Here a wrote up a smaller version of something like that to show you how you could trim it down

Heres the code with an example

```MsgBox(0 , "Random Password", randompass("8"))

Func RandomPass(\$length)
Local \$letter, \$password
For \$i = 1 To \$length
\$letter = Random(33, 126)
\$password = \$password & Chr(\$letter)
Next
Return \$password
Endfunc```

Edit : And for the set char lengths you could do

```MsgBox(0 , "Random Password", randompass("8"))

Func RandomPass(\$length)
Local \$letter, \$password
If \$length < 9 then
For \$i = 1 To \$length
\$letter = Random(33, 126)
\$password = \$password & Chr(\$letter)
Next
Return \$password
Else
Return "Length too long"
Endif
Endfunc```
Edited by killaz219

#### Share this post

##### Share on other sites

Thanks, that will work great.

Don't argue with an idiot; people watching may not be able to tell the difference.

#### Share this post

##### Share on other sites

Oops change the

`for \$i = 0 to \$length`
to

`for \$i = 1 to \$length`
Edited by killaz219

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now

• ### Recently Browsing   0 members

No registered users viewing this page.

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...