Creating Random Passwords
Tuesday, March 13, 2012
Posted by Priya Yadav
Creating a random password is a programming task you may have to handle if you own a website which has membership options. A visitorsigns up by entering their email address. Then you create a random password, assign it to that email address, and fire off an emailto the visitor with the random password in the email.
Why would you do this? It's a way of verifying that the visitor has entered a valid email address. If they entered a bogusemail address, the email will never get to them, and they'll never find out what their password is, and they won't be able to log in.
So, how do you create a randomly generated password
Here's what the code will look like:
Of course, that's just one numeric value, and we need a bunch of them strung together as a string variable. How longdo you want your password to be? Let's say it'll be 6 characters. So we need to do a loop six times:
That'll do it! You now have a random password containing nothing but upper case letters.
One thing that most people will tell you, though, is that passwords like this are very difficult to remember, sowebsites will often create random passwords which alternate between consonants and vowels. By doing this, you make itpossible for the visitor to pronounce the password, which makes it easier to remember.
So, how do we go about doing this? Well, there are a couple ways you can do it. One way is to create a function that generates vowels:
Then, of course, you create another function which generates a random consonant (this function will be a lot longer, right?). Onceyou have both of these functions, creating your random password is simple as:
Why would you do this? It's a way of verifying that the visitor has entered a valid email address. If they entered a bogusemail address, the email will never get to them, and they'll never find out what their password is, and they won't be able to log in.
So, how do you create a randomly generated password
Here's what the code will look like:
Dim RandomLetter As Integer |
Of course, that's just one numeric value, and we need a bunch of them strung together as a string variable. How longdo you want your password to be? Let's say it'll be 6 characters. So we need to do a loop six times:
Dim RandomLetter As Integer |
That'll do it! You now have a random password containing nothing but upper case letters.
One thing that most people will tell you, though, is that passwords like this are very difficult to remember, sowebsites will often create random passwords which alternate between consonants and vowels. By doing this, you make itpossible for the visitor to pronounce the password, which makes it easier to remember.
So, how do we go about doing this? Well, there are a couple ways you can do it. One way is to create a function that generates vowels:
Randomize Timer |
Then, of course, you create another function which generates a random consonant (this function will be a lot longer, right?). Onceyou have both of these functions, creating your random password is simple as:
Dim ThePassword As String
Dim Index As Integer
Randomize Timer
'Get Random Letters
For Index = 1 to 3
ThePassword = ThePassword & GetRandomConsonant()
ThePassword = ThePassword & GetRandomVowel()
Next Index
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
Programming
. Follow any responses to this post through RSS. You can leave a response, or trackback from your own site.
Subscribe to:
Post Comments (Atom)
Post a Comment