passwodrd genaration

  • Thread starter Thread starter krishna
  • Start date Start date
K

krishna

Hi,
I would like genarate of 6 alpha nuemaric characters
password automatically in ASP.NET.plz
how to make it.

Waiting for the reply.

krishna
 
I don't know about 'ASP' but in vb you could use this function:

....
Dim strPassword As String
Dim intCount As Integer
Try
For intCount = 0 To 5
strPassword &= GetRandomPasswordChar()
Next
....

Private Function GetRandomPasswordChar() As Char

Dim objRandom As Random
Dim objTimer As DateTime
Dim intChar As Integer
Dim intTicks As Integer
Dim dblStart As Double

Try
REM Create timer.
objTimer = New DateTime()
REM Get 'random' value for Random class constructor.
intTicks = Convert.ToInt32(DateTime.Now.Millisecond)
REM Wait for a few milliseconds to create different values.
dblStart = objTimer.Now.TimeOfDay.TotalMilliseconds()
While objTimer.Now.TimeOfDay.TotalMilliseconds() - dblStart < 13
Application.DoEvents()
End While
REM Create Random object.
objRandom = New Random(intTicks)
REM Get random value between 48 ('0') and 122 ('z').
intChar = objRandom.Next(48, 122)
REM Make sure character value is valid.
While (intChar > 57 And intChar < 65) Or (intChar > 90 And
intChar < 97)
intChar = objRandom.Next(48, 122)
End While
REM Return char.
Return Convert.ToChar(intChar)
Catch X As Exception
Return Convert.ToChar("-"c) ' Failed.
End Try

End Function
 
This would do the trick a little better. It still produces about 15
duplicant passwords out of 500 passwords 6 characters long.


Private Function GetRandomPasswordChar() As Char

Dim objRandom As Random
Dim objTimer As DateTime
Dim intChar, intWait As Integer
Dim lngTicks As Double
Dim dblStart As Double

Try
REM Create timer.
objTimer = New DateTime()
REM Get 'random' value for Random class constructor.
lngTicks = objTimer.Now.TimeOfDay.Ticks
While lngTicks >= 2147483647 ' Max value of integer
lngTicks /= 2
End While
REM Create Random object.
objRandom = New Random(Convert.ToInt32(lngTicks))
REM Get random value between 10 and 50.
intWait = objRandom.Next(10, 50)
REM Wait for a few milliseconds to create different values.
dblStart = objTimer.Now.TimeOfDay.TotalMilliseconds()
While objTimer.Now.TimeOfDay.TotalMilliseconds() - dblStart <
intWait
Application.DoEvents()
End While
REM Get random value between 48 ('0') and 122 ('z').
intChar = objRandom.Next(48, 122)
REM Make sure character value is valid.
While (intChar > 57 And intChar < 65) Or (intChar > 90 And
intChar < 97)
intChar = objRandom.Next(48, 122)
End While
REM Return char.
Return Convert.ToChar(intChar)
Catch X As Exception
Return Convert.ToChar("-"c) ' Failed.
End Try

End Function
 
Qwert said:
objRandom = New Random(Convert.ToInt32(lngTicks))

The paramterless constructor of 'Random' will use a clock-based seed value
automatically.
 

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

Back
Top