generate random password

M

MattB

I have the following code to generate random passwords for new users of
an application.

Const chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstyvwxyz1234567890"

Dim r As Int16, i As Int16
Dim Pswd As String = ""

For i = 1 To len
r = Int((Rnd() * 62) + 1)
Pswd = Pswd & Mid(chars, r, 1)
Next i
Return Pswd

------------

It runs alright, but in the pas couple of days it seems the first time I
run it after starting my asp.net application I always get this same
password: rhjRSwAv

I've actually gotten it three times today. That's not quite random
enough for me. Am I doing something wrong? What can I do to this code to
make the passwords less predictable? Thanks!

Matt
 
J

JV

Randomizers on a computer are not really very random. Usually one varies a
randomizer by passing it a different seed value each time it is used. You
can use something like the number of timer ticks or maybe the number of
milliseconds reported from DateTime.Now. It's up to you to come up with a
"random enough" scheme.
 
V

Vishnu-Chivukula

Hi Matt

Dont know if this is what you are looking for.
If your need is to create a unique value (temporary password) for a given
user and let him use that only once to log into your site and then ask him
to change his password after that, then you can use Globally Unique
IDentifier GUID in the System namespace.

GUID is a 128-bit integer (16 bytes).

HTH,

Happy Coding

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemguidclasstopic.asp
 
J

John Timney \(ASP.NET MVP\)

I have seen people take that code, and get the statement to pick two random
words and concatonate them to create a new word. So you have two arrays for
example loaded with words, monkey,day,nuts,tree etc....randomise your choice
and get a decent password generator thats not just random letters and
numbers - it makes usability a lot easier.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
H

Hans Kesting

MattB said:
I have the following code to generate random passwords for new users of
an application.

Const chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstyvwxyz1234567890"

Just a word of warning: in some fonts "I", "l" and "1" are very
similar. The same goes for "0", "O" and (maybe) "o". You might
want to leave them out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top