Generate password

M

Morten Snedker

I'm using this for generating passwords. It seems to function okay.
Anything you guys reckon I missed out on?


'** CODE BEGIN
Public Class GeneratePassword

Public Shared Function GeneratePassword(ByVal Length As
Integer, ByVal Complexity As Complexity) As String

Dim characters As String =
"abcdefghijklmnopqrstuvwxyz1234567890"

If Complexity = Complexity.Medium Or Complexity =
Complexity.Complex Then
characters += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
End If

If Complexity = Complexity.Medium Then
characters += "!#%&/()=? "
End If

Dim password As String = ""
Dim random As New Random

For i As Integer = 0 To Length
password += characters.Substring(random.Next(0,
characters.Length - 1), 1)
Next

Return password

End Function

Public Enum Complexity
Simple
Medium
Complex
End Enum

End Class
'** CODE END

Regards /Snedker
 
R

rowe_newsgroups

I'm using this for generating passwords. It seems to function okay.
Anything you guys reckon I missed out on?

'** CODE BEGIN
Public Class GeneratePassword

Public Shared Function GeneratePassword(ByVal Length As
Integer, ByVal Complexity As Complexity) As String

Dim characters As String =
"abcdefghijklmnopqrstuvwxyz1234567890"

If Complexity = Complexity.Medium Or Complexity =
Complexity.Complex Then
characters += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
End If

If Complexity = Complexity.Medium Then
characters += "!#%&/()=? "
End If

Dim password As String = ""
Dim random As New Random

For i As Integer = 0 To Length
password += characters.Substring(random.Next(0,
characters.Length - 1), 1)
Next

Return password

End Function

Public Enum Complexity
Simple
Medium
Complex
End Enum

End Class
'** CODE END

Regards /Snedker

I've always used the .NET Web component to generate my passwords:

//////////////////////
Option Strict On

'// Add reference to System.Web
Imports System.Web.Security

Module Module1

Sub Main()
Dim password As String = Membership.GeneratePassword(7, 3)

Console.WriteLine(password)

Console.Read()
End Sub

End Module
//////////////////////

Thanks,

Seth Rowe [MVP]
 
F

Family Tree Mike

Your medium and complex modes do not force the generator to pick from the
other datasets, even though you add them to the list of random characters.
This means that in a given scenario, even if you pass in "complex", you could
get a password of "boogiewoogie" (just an example, all from the lower case).
Random doesn't guarantee one from each set, is what I am getting at. Our
company requres the complex set, but at least one from each group.
 
M

Morten Snedker

You certainly got a point there that I missed myself. Thanks for your input.

Back to the drawing table :)

Regards /Snedker

Family Tree Mike skrev:
 
M

Mythran

Morten Snedker said:
You certainly got a point there that I missed myself. Thanks for your
input.

Back to the drawing table :)

Regards /Snedker

Family Tree Mike skrev:

I wouldn't just go about getting 1 complex/medium value per password either.
I would randomize the position in the password the special characters and/or
upper case chars go as well....but wouldn't go all out and do complete
randomization. If you did that, you could end up with ##### as the password
:p

HTH,
Mythran
 
J

Jonathan Boivin

If I could give an advice on your method, in fact, what I would do.. is :
Generate a password with your lower security set of characters. Then upper
case randomizally some letters and finally inserts special chars at
randomized positions.

I don't know if you like the proposition, but it can help.

Jonathan Boivin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top