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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password generator

Status
Not open for further replies.

ozzroo

Technical User
Feb 28, 2003
182
0
0
AU
I have a registration page that creates a new user account. I was wondering I would I create a random alpanumeric password (in the password field) for each new registration in an sql server database. would it be best to use a stored procedure or do it through .net code.

if the first option is best, how do i incorporate/run the store procedure from my registration page and ensures it inserts into the new registration

thanks
 
Hi ozzroo,

The Membership.GeneratePassword method seems to generate rather complicated passwords although I believe you can tweak this (ca8msm ?)

I use this function that turns a Guid into an alphanumeric password

Code:
Public Function GetRandomPasswordUsingGUID(ByVal length As Integer) As String

        'Get the GUID
        Dim guidResult As String = System.Guid.NewGuid().ToString()

        'Remove the hyphens
        guidResult = guidResult.Replace("-", String.Empty)

        'Return the first length bytes
        Return guidResult.Substring(0, length)

    End Function

just pass along the number of characters you want such as

Dim _Password As String = GetRandomPasswordUsingGUID(8)
Membership.CreateUser(txtUsername.Text, _Password, txtEmail.Text)

HTH,

Jon

 
The Membership.GeneratePassword method seems to generate rather complicated passwords although I believe you can tweak this (ca8msm ?)
The method takes two parameters; length and numberOfNonAlphanumericCharacters

The numberOfNonAlphanumericCharacters is actually the minimum number of punctuation characters included in the returned string (as opposed to the maximum which would then allow you not to include any), so you can't actually make the password less "complicated", although you could strip out these characters afterwards if you really wanted. Personally, I prefer to leave them in to make the password more secure.



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

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Thanks for your help guys.

I am creating the password perfectly with the punctuation characters. They are fine for now.

I may try the other function and see how it works

 
If you have found these posts helpful, you should mark each post by clicking the "Thank whatsthehampton for this valuable post!" under each relevant post. Otherwise, it doesn't show future readers which posts are helpful and makes your user stats look like you have only found one post out of 80 helpful.


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

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top