Random Password Needed

  • Thread starter Thread starter Les
  • Start date Start date
L

Les

I need to generate a random password entirely text. Is there an easy way to
do this.

This needs to be of 8 characters and cannot be repeated. I expect to need a
maximum of 800.

Thanks

Les
 
Here's a function for you.

Function RandomLetter(Optional Length As Integer = 8) As
String
Randomize
'For Upper case Only
Dim intLetter As Integer
Dim intCounter As Integer
' For intCounter = 1 To Length
' intLetter = Int(Rnd(1) * 26 + 65)
' RandomLetter = RandomLetter & Chr$(intLetter)
' Next intCounter

'For Mixed Case
Dim intUpper As Integer
For intCounter = 1 To Length
intUpper = Int(Rnd(1) * 2)
If intUpper Then
intLetter = Int(Rnd(1) * 26 + 65)
Else
intLetter = Int(Rnd(1) * 26 + 97)
End If
RandomLetter = RandomLetter & Chr$(intLetter)
Next intCounter
End Function


There's no check for duplicity, but the chances are very
slim that it would happen.

Chris
 
Chris thanks for this it's just what I need.

Do you by any chance have the code so I can run an update query and update
the whole table in one go my table is "tblAssociate_Details and the field"
name is "strAsssociate_Password"

Thanks

Les
 
Hi Les

You can use a user-defined function in an update query, but you need to fool
the query optimizer. You might expect this to work::

Update tblAssociate_Details set strAssociate_Password = RandomLetter()

However, because no argument is being passed to the function, the optimizer
assumes the same result will be returned every time, so your function will
be called only once and every record will get the same password.

You can trick it by passing the primary key of the record as a dummy
argument:

Function RandomLetter(Optional Length As Integer = 8, _
Optional Dummy as Variant) As String

Then, the SQL:

Update tblAssociate_Details
set strAssociate_Password = RandomLetter(8, AssociateID)
 
Graham thanks for this.

I don't think I have fully understood where to put the last 2 lines you
quote as im still getting the same password in each record. Can you confirm
the position of the last 2 lines please. Do I call the function name from
the update query?

Update tblAssociate_Details
set strAssociate_Password = RandomLetter(8, AssociateID)

Thanks

Les


Graham Mandeno said:
Hi Les

You can use a user-defined function in an update query, but you need to fool
the query optimizer. You might expect this to work::

Update tblAssociate_Details set strAssociate_Password = RandomLetter()

However, because no argument is being passed to the function, the optimizer
assumes the same result will be returned every time, so your function will
be called only once and every record will get the same password.

You can trick it by passing the primary key of the record as a dummy
argument:

Function RandomLetter(Optional Length As Integer = 8, _
Optional Dummy as Variant) As String

Then, the SQL:

Update tblAssociate_Details
set strAssociate_Password = RandomLetter(8, AssociateID)

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


Les said:
Chris thanks for this it's just what I need.

Do you by any chance have the code so I can run an update query and update
the whole table in one go my table is "tblAssociate_Details and the field"
name is "strAsssociate_Password"

Thanks

Les
 
Hi Les

Yes, those two lines are the SQL statement for the update query.

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


Les said:
Graham thanks for this.

I don't think I have fully understood where to put the last 2 lines you
quote as im still getting the same password in each record. Can you confirm
the position of the last 2 lines please. Do I call the function name from
the update query?

Update tblAssociate_Details
set strAssociate_Password = RandomLetter(8, AssociateID)

Thanks

Les


Graham Mandeno said:
Hi Les

You can use a user-defined function in an update query, but you need to fool
the query optimizer. You might expect this to work::

Update tblAssociate_Details set strAssociate_Password = RandomLetter()

However, because no argument is being passed to the function, the optimizer
assumes the same result will be returned every time, so your function will
be called only once and every record will get the same password.

You can trick it by passing the primary key of the record as a dummy
argument:

Function RandomLetter(Optional Length As Integer = 8, _
Optional Dummy as Variant) As String

Then, the SQL:

Update tblAssociate_Details
set strAssociate_Password = RandomLetter(8, AssociateID)

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


Les said:
Chris thanks for this it's just what I need.

Do you by any chance have the code so I can run an update query and update
the whole table in one go my table is "tblAssociate_Details and the field"
name is "strAsssociate_Password"

Thanks

Les


Here's a function for you.

Function RandomLetter(Optional Length As Integer = 8) As
String
Randomize
'For Upper case Only
Dim intLetter As Integer
Dim intCounter As Integer
' For intCounter = 1 To Length
' intLetter = Int(Rnd(1) * 26 + 65)
' RandomLetter = RandomLetter & Chr$(intLetter)
' Next intCounter

'For Mixed Case
Dim intUpper As Integer
For intCounter = 1 To Length
intUpper = Int(Rnd(1) * 2)
If intUpper Then
intLetter = Int(Rnd(1) * 26 + 65)
Else
intLetter = Int(Rnd(1) * 26 + 97)
End If
RandomLetter = RandomLetter & Chr$(intLetter)
Next intCounter
End Function


There's no check for duplicity, but the chances are very
slim that it would happen.

Chris



-----Original Message-----
I need to generate a random password entirely text. Is
there an easy way to
do this.

This needs to be of 8 characters and cannot be repeated.
I expect to need a
maximum of 800.

Thanks

Les



.
 
Great got it now thanks Graham

Les


Graham Mandeno said:
Hi Les

Yes, those two lines are the SQL statement for the update query.

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


Les said:
Graham thanks for this.

I don't think I have fully understood where to put the last 2 lines you
quote as im still getting the same password in each record. Can you confirm
the position of the last 2 lines please. Do I call the function name from
the update query?

Update tblAssociate_Details
set strAssociate_Password = RandomLetter(8, AssociateID)

Thanks

Les


Graham Mandeno said:
Hi Les

You can use a user-defined function in an update query, but you need
to
fool
the query optimizer. You might expect this to work::

Update tblAssociate_Details set strAssociate_Password = RandomLetter()

However, because no argument is being passed to the function, the optimizer
assumes the same result will be returned every time, so your function will
be called only once and every record will get the same password.

You can trick it by passing the primary key of the record as a dummy
argument:

Function RandomLetter(Optional Length As Integer = 8, _
Optional Dummy as Variant) As String

Then, the SQL:

Update tblAssociate_Details
set strAssociate_Password = RandomLetter(8, AssociateID)

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


Chris thanks for this it's just what I need.

Do you by any chance have the code so I can run an update query and update
the whole table in one go my table is "tblAssociate_Details and the field"
name is "strAsssociate_Password"

Thanks

Les


Here's a function for you.

Function RandomLetter(Optional Length As Integer = 8) As
String
Randomize
'For Upper case Only
Dim intLetter As Integer
Dim intCounter As Integer
' For intCounter = 1 To Length
' intLetter = Int(Rnd(1) * 26 + 65)
' RandomLetter = RandomLetter & Chr$(intLetter)
' Next intCounter

'For Mixed Case
Dim intUpper As Integer
For intCounter = 1 To Length
intUpper = Int(Rnd(1) * 2)
If intUpper Then
intLetter = Int(Rnd(1) * 26 + 65)
Else
intLetter = Int(Rnd(1) * 26 + 97)
End If
RandomLetter = RandomLetter & Chr$(intLetter)
Next intCounter
End Function


There's no check for duplicity, but the chances are very
slim that it would happen.

Chris



-----Original Message-----
I need to generate a random password entirely text. Is
there an easy way to
do this.

This needs to be of 8 characters and cannot be repeated.
I expect to need a
maximum of 800.

Thanks

Les



.
 
Back
Top