A password generator

cameron_kyle

Active Member
Joined
Jan 14, 2006
Messages
313
Can someone help me?

In column A I have a code i.e. 9458W and in column B I have a clients name i.e. Adrian Goodwill

In column D I was wondering if there was a way to generate a random 8 figure password from by combining the information from column A and B, this needs to be a random unique password anything will do as long as it has 8 figures combining letters and numbers from A and B in column


thanks kyle
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I concatenated cols A & B, then used

MID(H12,RANDBETWEEN(1,LEN(H12)),1)&MID(H12,RANDBETWEEN(1,LEN(H12)),1)


to generate the first 2 characters.

You could possibly extend this.
 
Upvote 0
Another way:
For random password generators I usually just use a VBA function. You can use a formula with Rand, but the password will change everytime you go to recalculate cells. (Which is not to my personal taste) Here is some sample code:
(There are shorter ways to do this, but I tried to write this in such a way that you can take it apart and understand the concepts if you so choose)
Rich (BB code):
Sub PasswordGenerator()
Dim Password As String
Dim PasswordLength As Byte
Dim LC As Byte                  'Loop Counter
Dim strRndmChr As String
Dim LAC As Byte                 'Lowest Ascii Character
Dim HAC As Byte                 'Highest Ascii Character
Dim UseSymbolics As Boolean
Dim HasSymbolics As Boolean
Dim RandomNumber As Byte
'Set parameters.
PasswordLength = 8
'Visit www.lookuptables.com for the ascii table.
LAC = Asc("0")
HAC = Asc("z")
UseSymbolics = False

Randomize
For LC = 1 To PasswordLength
    'To produce random integers in a given range, use this formula:
    'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
    Do
        RandomNumber = Int((HAC - LAC + 1) * Rnd + LAC)
        strRndmChr = Chr(RandomNumber)
        HasSymbolics = CheckSymbolics(RandomNumber)
    Loop Until UseSymbolics = True Or HasSymbolics = False
    Password = Password & strRndmChr
Next LC
ActiveCell = Password
End Sub
Private Function CheckSymbolics(RandomNumber As Byte)
If (RandomNumber >= 33 And RandomNumber <= 47) Or _
    (RandomNumber >= 58 And RandomNumber <= 64) Or _
    (RandomNumber >= 91 And RandomNumber <= 96) Or _
    (RandomNumber >= 123 And RandomNumber <= 126) Then _
    CheckSymbolics = True Else: CheckSymbolics = False
End Function
 
Upvote 0
Ok, nothing fancy, nothing random but here's a quick formula...

"A I have a code i.e. 9458W and in column B I have a clients name i.e. Adrian Goodwill "

So..
A B D
9458W Adrian Goodwill Adrill94

D1 formula:
=LEFT(B1,3)&RIGHT(B1,3)&LEFT(A1,2)
This takes the first 3 characters of Adrian, the last 3 of Goodwill and the first 2 of 9458W...

Just copy/paste down column D.
Note: If the Last name contains only 2 letters, "Patrich Jo" the formula will return the space...:
Pat Jo94

Simple but not the best.
Lupin
 
Upvote 0
change of mind

There seems to be something wrong with the formula,

I have come to see that it doesn’t mater what figures are placed in column D there is no need for a relation between what is in A and B,
All I need is there a formula that will automatically generate a random array of 8 figures alpha numeric, with mixed case, but this is not essential

NB this however needs to be totally unique, I ant afford to have two passwords the same

Any suggestions
 
Upvote 0
Hi Cameron,

Who's formula ?

Oorang's code, Steve059L's formula or mine (Lupin)...

Does the formula work?
Or is it that you are not happy with the results (which is OK, no pun)

Lupin
 
Upvote 0
Re: change of mind

Hello,

Any suggestions
Yes. The way I generate Random Alpha Numeric Chars is with rndStr(), as seen below. The trick is to simply stack keyArr, your array holding the possible characters, with the appropriate characters, and you're in like Flynn.

To ensure X amount of Unique returns, you'll want some additional VBA in the form of a routine that populates an array of returns, first checking to make sure our return is not already in the array. For this example, foobar creates 100, unique, random returns, the upper boundary of the first vector of strArr:

<font face=Courier New><SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Function</SPAN> rndStr(<SPAN style="color:darkblue">ByRef</SPAN> StrLength <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> b() <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Byte</SPAN>, keyArr() <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Byte</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> i <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Let</SPAN> keyArr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
<SPAN style="color:darkblue">ReDim</SPAN> b(1 <SPAN style="color:darkblue">To</SPAN> StrLength * 2)
<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> StrLength * 2 <SPAN style="color:darkblue">Step</SPAN> 2
    <SPAN style="color:darkblue">Let</SPAN> b(i) = keyArr(Int(((UBound(keyArr) + 1) \ 2) * Rnd + 1) * 2 - 2)
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">Let</SPAN> rndStr = b
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>

<SPAN style="color:darkblue">Sub</SPAN> foobar()
<SPAN style="color:darkblue">Dim</SPAN> strArr(1 <SPAN style="color:darkblue">To</SPAN> 100, 1 <SPAN style="color:darkblue">To</SPAN> 1) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> tmpStr <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, i <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">For</SPAN> i = <SPAN style="color:darkblue">LBound</SPAN>(strArr) <SPAN style="color:darkblue">To</SPAN> <SPAN style="color:darkblue">UBound</SPAN>(strArr)
    <SPAN style="color:darkblue">Let</SPAN> tmpStr = rndStr(8)
    <SPAN style="color:darkblue">If</SPAN> IsNumeric(Application.Match(tmpStr, strArr, 0)) <SPAN style="color:darkblue">Then</SPAN>
        <SPAN style="color:darkblue">Do</SPAN> <SPAN style="color:darkblue">Until</SPAN> <SPAN style="color:darkblue">Not</SPAN> IsNumeric(Application.Match(tmpStr, strArr, 0))
            <SPAN style="color:darkblue">Let</SPAN> tmpStr = rndStr(8)
        <SPAN style="color:darkblue">Loop</SPAN>
    <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Let</SPAN> strArr(i, 1) = tmpStr
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">Let</SPAN> Range("a1").Resize(UBound(strArr, 1)).Value = strArr
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>

To generate more or less returns, change the upper boundary of strArr from 100 to whatever. And the example places the returns in A1:AX, where X is also the upper boundary of strArr. To change the top cell as to where this array gets dumped, change A1 to wherever you please.

Hope this helps. :)
 
Upvote 0
This works pretty quickly on 100 returns. Took about 1:24 mm:ss on 10,000 unique, random String returns...

rndStr() is really fast, so I'm assuming the bottle-neck is the Match() call, peeking at the larger array for a matching String... Perhaps eliminating duplication...

Still works as advertised, though. :)


Edited by Nate:

Took about 1:23 mm:ss on 10,000 unique, random String returns with the following:

<font face=Courier New><SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Function</SPAN> rndStr(<SPAN style="color:darkblue">ByRef</SPAN> StrLength <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> b() <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Byte</SPAN>, keyArr() <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Byte</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> i <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Let</SPAN> keyArr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
<SPAN style="color:darkblue">ReDim</SPAN> b(1 <SPAN style="color:darkblue">To</SPAN> StrLength * 2)
<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> StrLength * 2 <SPAN style="color:darkblue">Step</SPAN> 2
    <SPAN style="color:darkblue">Let</SPAN> b(i) = keyArr(Int(((UBound(keyArr) + 1) \ 2) * Rnd + 1) * 2 - 2)
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">Let</SPAN> rndStr = b
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>

<SPAN style="color:darkblue">Sub</SPAN> foobar()
<SPAN style="color:darkblue">Dim</SPAN> strArr(1 <SPAN style="color:darkblue">To</SPAN> 10000, 1 <SPAN style="color:darkblue">To</SPAN> 1) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> tmpStr <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>, i <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> Now
<SPAN style="color:darkblue">For</SPAN> i = <SPAN style="color:darkblue">LBound</SPAN>(strArr) <SPAN style="color:darkblue">To</SPAN> <SPAN style="color:darkblue">UBound</SPAN>(strArr)
    <SPAN style="color:darkblue">Let</SPAN> tmpStr = rndStr(8)
    <SPAN style="color:darkblue">If</SPAN> IsNumeric(Application.Match(tmpStr, strArr, 0)) <SPAN style="color:darkblue">Then</SPAN>
        Do: <SPAN style="color:darkblue">Let</SPAN> tmpStr = rndStr(8)
        <SPAN style="color:darkblue">Loop</SPAN> <SPAN style="color:darkblue">While</SPAN> IsNumeric(Application.Match(tmpStr, strArr, 0))
    <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Let</SPAN> strArr(i, 1) = tmpStr
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">Let</SPAN> Range("a1").Resize(UBound(strArr, 1)).Value = strArr
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> Now
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN>
</FONT>

Pretty much, the same result...
 
Upvote 0

Forum statistics

Threads
1,222,729
Messages
6,167,880
Members
452,152
Latest member
PinHeads

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top