Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create randomly generated alphanumeric password

Status
Not open for further replies.

Griffinator

Programmer
Dec 30, 2002
28
CA
Hi all,

I was wondering if anyone knows how to randomly generate a 6-digit alphanumeric password in an application. For example, if the user clicks a "Generate Password" command button, the application will generate a password such as "abks$1" (without the quotes). Any combination of numbers and letters will do, it just needs to be random for security reasons.

Thanks in advance
 
u could use the randomize rnd function and chr function...

ie something like

Private Sub generate_Click()

Randomize Val(CStr(Now))

For i = 1 To 6
result = Int(256 * Rnd)
result = Chr(result)
Text1 = Text1 & result
Next i

End Sub

not very secure but

good luck!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
I don't Have VB where I am right now at home.

But what you want to do, is simply run rnd, that's a function and set it';s values to the allowable ascii ones.

So it would be...

For 1 = 1 to 6
strPass = strPass & keyascii(rnd need the rnd low and high here))
next i

Craig, mailto:sander@cogeco.ca

In the computer industry, there are three kinds of lies:
lies, damn lies, and benchmarks.
 
NM CHR$ is right... acii is the reverse of that...

Craig, mailto:sander@cogeco.ca

In the computer industry, there are three kinds of lies:
lies, damn lies, and benchmarks.
 
Excellent!!!

Thanks guys, this is exactly what I was looking for. I wasn't sure where to start!

I will reply back if I have any further questions (I am not near my computer right now, either)

Take care!
 
with regards to my reply using Now isnt very practical, since the variation of rnd within a day is limited...

try:-

Randomize Val(CStr(Time))

instead...

good luck!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
strongm:

>not very secure

i did say that!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
It is not just a question of basic security, it is the fact that machine generated passwords are often difficult for humans to remember. SO the first thing that they do is to write them down. Which immediately compromises security.

Lots of people forget that securty involves humans and their quirks and that, what from a technical seems like a solid idea, in reality is not.
 
ADoozer,
FYI: Randomize without an argument uses the system timer as a seed, so the Val and Cstr are probably redundant


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
And now in English. The following sentence:

Lots of people forget that securty involves humans and their quirks and that, what from a technical seems like a solid idea, in reality is not.

should read

Lots of people forget that security involves humans and their quirks and that what, from a technical point of view, seems like a solid idea in reality is not.
 
That is a very valid point, strongm.

The reason for this password is to create a "Master" password, kind of like a fail-safe in the instance that another user decides to completely lock out all users on the system. This password will be known by one (and only one user, most likely the owner of the software), and is to be kept in a secure location (a safe, etc.). I am playing with the idea of allowing the user to specify the password if so desired, but would like it to default to something random when the app is set up.
 
hmm... yes, yes it does... o well... (i always use it with queryperformancecounter)

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top