Excel VB | random password generator
There are a few of way I like to create random passwords usually from a Filemaker server based database, for more security, but here is an Excel visual basic equivalent of what I use:
Random Password Generator
This code below generates passwords completely randomly.
Public Function RndPass(Length As Integer, Optional Lower As Boolean) As String
Dim Max As Integer
Dim Min As IntegerDim RndPassLoop As String
Max = 126
Min = 48Randomize Timer
If Length < 8 Then
Length = 8
End IfFor i = 1 To Length
RndPassLoop = RndPassLoop & Chr(Int((Max - Min + 1) * Rnd + Min))
Next iIf Lower = False Then
RndPass = RndPassLoop
Else
RndPass = StrConv(RndPassLoop, vbLowerCase)
End IfEnd Function
‘add this code to a vb module
’syntax is RndPass(Length of password, True (lowercase) / Empty or False (both upper and lower)
‘RndPass(20,1) = 20 characters lower case
Random Letter Generator
This code below will generator code for a random letter or number based string.
Public Function RndLetter(LowerLimit As Integer, UpperLimit As Integer, TheType As Integer)
Dim Rand As String
Dim i As Integer, RndNo As Integer, SetType As Integer
Dim MyCase As Integer
Application.Volatile
Select Case TheType
Case Is = “1″ ‘Upper case
MyCase = 65: SetType = 26
Case Is = “2″ ‘Lower Case
MyCase = 97: SetType = 26
Case Is = “3″ ‘Leading Capital
MyCase = 97: SetType = 26
Case Is = “4″ ‘Text digits
MyCase = 48: SetType = 10
Case Is = “5″ ‘Numeric digits
MyCase = 48: SetType = 10
End Select
If TheType = 3 Then ‘Set leading character of “Name”
i = i + 1
Randomize
Rand = Rand & Chr(Int((26) * Rnd + 65))
End If
‘Set random length of string
RndNo = Int((UpperLimit + 1 - LowerLimit) * Rnd + LowerLimit)
Do
i = i + 1
Randomize
Rand = Rand & Chr(Int((SetType) * Rnd + MyCase))
Loop Until i = RndNo
RndLetter = Rand
‘Convert string to number
If TheType = 5 Then RndLetter = RndLetter * 1
End Function‘add this code to a vb module
’syntax is RndLetter(Smallest Random Letter Length, Largest Random Letter Length / Type 1-5 (Uppercase, Lowercase, Leading Capital, Text Digits, Numeric Digits)
‘RndLetter(10,10,5) = 7580774271 (Numeric digits)
Password from Phrase Generator
Here is my code to convert a phrase or sentence to a secure password but with a structure to it. I find this useful - it replaces a number of set letters (that you can define yourself) from the given string phrase. All you need to do is remember the phrase you use and you can re-generate your password - I usually use this for passwords I don’t use regularly, would forget and that aren’t as easy to reset.
Not that I recommend this, but it means you can also write the phrase down somewhere. (I use distinct phrases but you can use nice simple ones like your birthday “January 1st 1990″ or the name of your partner - since if someone saw them written down they wouldn’t instantly look like a password).
Excel isn’t the most secure carrier of code for a password generator unless you compile it to a dll file - so make sure you don’t use silly filenames and keep it secure.
Public Function RndPassP(Phrase As String) As String
Dim Max As Integer
Dim Min As IntegerDim RndPassLoop As String
If Len(Phrase) < 12 Then
RndPassP = “Phrase too short - please choose something longer”
Exit Function
End IfIf subStringCount(Phrase, “a”) + _
subStringCount(Phrase, “c”) + _
subStringCount(Phrase, “e”) + _
subStringCount(Phrase, “i”) + _
subStringCount(Phrase, “o”) + _
subStringCount(Phrase, “s”) + _
subStringCount(Phrase, “u”) + _
subStringCount(Phrase, “r”) < 4 ThenRndPassP = “Phrase does not include enough key letters - please choose another”
Exit Function
End IfPhrase = StrConv(Phrase, vbLowerCase)
Randomize Timer
RndPassLoop = Replace(Phrase, “a”, “@”)
Phrase = Replace(RndPassLoop, “b”, “8″)
RndPassLoop = Replace(Phrase, “e”, “3″)
Phrase = Replace(RndPassLoop, “i”, “!”)
RndPassLoop = Replace(Phrase, “o”, “0″)
Phrase = Replace(RndPassLoop, “s”, “$”)
RndPassLoop = Replace(Phrase, ” “, “”)
Phrase = Replace(RndPassLoop, “u”, “*”)
RndPassLoop = Replace(Phrase, “r”, “£”)
Phrase = Replace(RndPassLoop, “m”, “M”)
RndPassLoop = Replace(Phrase, “n”, “N”)
Phrase = Replace(RndPassLoop, “t”, “T”)
RndPassLoop = Replace(Phrase, “x”, “X”)
Phrase = Replace(RndPassLoop, “g”, “G”)Phrase = RndPassLoop & “:)”
RndPassP = Phrase
End Function
Function subStringCount(longString As String, subString As String) As Double
subStringCount = Len(longString) _
- Len(Application.Substitute(longString, subString, vbNullChar))
End Function‘add this code to a vb module
’syntax is ‘RndPassP(string):
‘RndPassP(”I work in Property Finance”)
Let me know what you think about these and what sort of password system you use?
Related Posts
About
You’re currently reading “Excel VB | random password generator”.
- Published:
- Monday, August 18th, 2008
- Author:
- Simon Page
- Category:
- Excel
- Tags:
- downloads, excel 2003, excel 2007, free, security, vb, vba, visual basic
What I'm Doing
- Happy Filemaker 10 day - loving it. (2 hrs ago) more...
Featured Posts
- 20 of the Best Amazing Photoshop Tutorials
- Best Video Games in 2008
- Canon IXUS - Macro Photo Gallery
- Creative LEGO art design
- Design Inspiration | typography posters
- Inspiring Gallery of Video Game Concept Art
- Must Have Christmas Gadgets
- Resources of Creative Design Inspiration
- Sony HDR TG3 Full HD Digital Camcorder
- The Best iPod Touch Accessories
- Top 10 Gadgets for 2009
- Top Christmas Electronics
Categories
- Creative Design (46)
- Excel (11)
- Filemaker (5)
- Gadgets (23)
- Gaming (15)
- Music (4)
- Random (4)
- Technology (4)




No comments
Jump to comment form | comments rss | trackback uri