Auto-generate Password

A

Antonio

Hello, everyone...I just thought of something to implement in my
database...How could I have the database auto-generate a username and
password? Of course there can't be duplicates. I have a username and
password field that are assigned to customers subscribing to online products.
Any ideas? Thanks
 
A

Arvin Meyer

Antonio said:
Hello, everyone...I just thought of something to implement in my
database...How could I have the database auto-generate a username and
password? Of course there can't be duplicates. I have a username and
password field that are assigned to customers subscribing to online products.
Any ideas? Thanks

Here's some code that will generate a password. Just enter the number of
characters you want. It includes "special characters" and a space, so make
sure your system will handle them, or remove them from the list:

Public Function fGenRandomString(intCharCount As Integer) As String
Dim i As Integer
Dim intPos As Integer
Dim strOut As String
Dim strOne As String * 1
Dim strCharPool As String
Const strChars =
"abcdegghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789~
@!#$%^&*()+{}]["

strCharPool = strChars
strOut = ""
If Not intCharCount > Len(strChars) Then
Randomize
For i = 1 To intCharCount
intPos = Int(Len(strCharPool) * Rnd + 1)
strOne = Mid(strCharPool, intPos, 1)
strCharPool = Left(strCharPool, intPos - 1) & Mid(strCharPool,
intPos + 1)
strOut = strOut & strOne
Next
Else
strOut = "Too Long"
End If
fGenRandomString = strOut
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
A

Antonio

Thanks, Arvin, I will try it and post the findings.

Antonio

Arvin Meyer said:
Antonio said:
Hello, everyone...I just thought of something to implement in my
database...How could I have the database auto-generate a username and
password? Of course there can't be duplicates. I have a username and
password field that are assigned to customers subscribing to online products.
Any ideas? Thanks

Here's some code that will generate a password. Just enter the number of
characters you want. It includes "special characters" and a space, so make
sure your system will handle them, or remove them from the list:

Public Function fGenRandomString(intCharCount As Integer) As String
Dim i As Integer
Dim intPos As Integer
Dim strOut As String
Dim strOne As String * 1
Dim strCharPool As String
Const strChars =
"abcdegghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789~
@!#$%^&*()+{}]["

strCharPool = strChars
strOut = ""
If Not intCharCount > Len(strChars) Then
Randomize
For i = 1 To intCharCount
intPos = Int(Len(strCharPool) * Rnd + 1)
strOne = Mid(strCharPool, intPos, 1)
strCharPool = Left(strCharPool, intPos - 1) & Mid(strCharPool,
intPos + 1)
strOut = strOut & strOne
Next
Else
strOut = "Too Long"
End If
fGenRandomString = strOut
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
A

Antonio

Arvin,

Everytime I try to reference to the function, I get an "Argument not
Optional" error message. I created a module and I am trying to call it from
a cmdbutton. Thanks, Antonio

Arvin Meyer said:
Antonio said:
Hello, everyone...I just thought of something to implement in my
database...How could I have the database auto-generate a username and
password? Of course there can't be duplicates. I have a username and
password field that are assigned to customers subscribing to online products.
Any ideas? Thanks

Here's some code that will generate a password. Just enter the number of
characters you want. It includes "special characters" and a space, so make
sure your system will handle them, or remove them from the list:

Public Function fGenRandomString(intCharCount As Integer) As String
Dim i As Integer
Dim intPos As Integer
Dim strOut As String
Dim strOne As String * 1
Dim strCharPool As String
Const strChars =
"abcdegghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789~
@!#$%^&*()+{}]["

strCharPool = strChars
strOut = ""
If Not intCharCount > Len(strChars) Then
Randomize
For i = 1 To intCharCount
intPos = Int(Len(strCharPool) * Rnd + 1)
strOne = Mid(strCharPool, intPos, 1)
strCharPool = Left(strCharPool, intPos - 1) & Mid(strCharPool,
intPos + 1)
strOut = strOut & strOne
Next
Else
strOut = "Too Long"
End If
fGenRandomString = strOut
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
D

Douglas J. Steele

How are you calling the function?

The way Arvin wrote it, you must pass the number of characters you want in
the string:

For instance, fGenRandomString(8) will return an 8 character string.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Antonio said:
Arvin,

Everytime I try to reference to the function, I get an "Argument not
Optional" error message. I created a module and I am trying to call it from
a cmdbutton. Thanks, Antonio

Arvin Meyer said:
Antonio said:
Hello, everyone...I just thought of something to implement in my
database...How could I have the database auto-generate a username and
password? Of course there can't be duplicates. I have a username and
password field that are assigned to customers subscribing to online products.
Any ideas? Thanks

Here's some code that will generate a password. Just enter the number of
characters you want. It includes "special characters" and a space, so make
sure your system will handle them, or remove them from the list:

Public Function fGenRandomString(intCharCount As Integer) As String
Dim i As Integer
Dim intPos As Integer
Dim strOut As String
Dim strOne As String * 1
Dim strCharPool As String
Const strChars =
"abcdegghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789~
@!#$%^&*()+{}]["

strCharPool = strChars
strOut = ""
If Not intCharCount > Len(strChars) Then
Randomize
For i = 1 To intCharCount
intPos = Int(Len(strCharPool) * Rnd + 1)
strOne = Mid(strCharPool, intPos, 1)
strCharPool = Left(strCharPool, intPos - 1) & Mid(strCharPool,
intPos + 1)
strOut = strOut & strOne
Next
Else
strOut = "Too Long"
End If
fGenRandomString = strOut
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
A

Antonio

from the button OnClick event I have fGenRandomString.

Antonio

Douglas J. Steele said:
How are you calling the function?

The way Arvin wrote it, you must pass the number of characters you want in
the string:

For instance, fGenRandomString(8) will return an 8 character string.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Antonio said:
Arvin,

Everytime I try to reference to the function, I get an "Argument not
Optional" error message. I created a module and I am trying to call it from
a cmdbutton. Thanks, Antonio

Arvin Meyer said:
Hello, everyone...I just thought of something to implement in my
database...How could I have the database auto-generate a username and
password? Of course there can't be duplicates. I have a username and
password field that are assigned to customers subscribing to online
products.
Any ideas? Thanks

Here's some code that will generate a password. Just enter the number of
characters you want. It includes "special characters" and a space, so make
sure your system will handle them, or remove them from the list:

Public Function fGenRandomString(intCharCount As Integer) As String
Dim i As Integer
Dim intPos As Integer
Dim strOut As String
Dim strOne As String * 1
Dim strCharPool As String
Const strChars =
"abcdegghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789~
@!#$%^&*()+{}]["

strCharPool = strChars
strOut = ""
If Not intCharCount > Len(strChars) Then
Randomize
For i = 1 To intCharCount
intPos = Int(Len(strCharPool) * Rnd + 1)
strOne = Mid(strCharPool, intPos, 1)
strCharPool = Left(strCharPool, intPos - 1) & Mid(strCharPool,
intPos + 1)
strOut = strOut & strOne
Next
Else
strOut = "Too Long"
End If
fGenRandomString = strOut
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
D

Douglas J. Steele

You must create an Event Procedure, and call the function in that procedure.
The function Arvin gave you cannot be used as an event.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


Antonio said:
from the button OnClick event I have fGenRandomString.

Antonio

Douglas J. Steele said:
How are you calling the function?

The way Arvin wrote it, you must pass the number of characters you want in
the string:

For instance, fGenRandomString(8) will return an 8 character string.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Antonio said:
Arvin,

Everytime I try to reference to the function, I get an "Argument not
Optional" error message. I created a module and I am trying to call
it
from
a cmdbutton. Thanks, Antonio

:

Hello, everyone...I just thought of something to implement in my
database...How could I have the database auto-generate a username and
password? Of course there can't be duplicates. I have a username and
password field that are assigned to customers subscribing to online
products.
Any ideas? Thanks

Here's some code that will generate a password. Just enter the number of
characters you want. It includes "special characters" and a space,
so
make
sure your system will handle them, or remove them from the list:

Public Function fGenRandomString(intCharCount As Integer) As String
Dim i As Integer
Dim intPos As Integer
Dim strOut As String
Dim strOne As String * 1
Dim strCharPool As String
Const strChars =
"abcdegghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789~
@!#$%^&*()+{}]["

strCharPool = strChars
strOut = ""
If Not intCharCount > Len(strChars) Then
Randomize
For i = 1 To intCharCount
intPos = Int(Len(strCharPool) * Rnd + 1)
strOne = Mid(strCharPool, intPos, 1)
strCharPool = Left(strCharPool, intPos - 1) & Mid(strCharPool,
intPos + 1)
strOut = strOut & strOne
Next
Else
strOut = "Too Long"
End If
fGenRandomString = strOut
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
A

Antonio

Maybe I am missing something...Create the module, then I was thinking about
firing it in 2 different ways...one way would be to create a "Generate
Password" button or after the user tabs away from the CustomerName text box,
use the txtcompanyname value to scramble it and generate the password. In
either case, wouldn't it be an Event Procedure? Antonio

Douglas J. Steele said:
You must create an Event Procedure, and call the function in that procedure.
The function Arvin gave you cannot be used as an event.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


Antonio said:
from the button OnClick event I have fGenRandomString.

Antonio

Douglas J. Steele said:
How are you calling the function?

The way Arvin wrote it, you must pass the number of characters you want in
the string:

For instance, fGenRandomString(8) will return an 8 character string.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Arvin,

Everytime I try to reference to the function, I get an "Argument not
Optional" error message. I created a module and I am trying to call it
from
a cmdbutton. Thanks, Antonio

:

Hello, everyone...I just thought of something to implement in my
database...How could I have the database auto-generate a username and
password? Of course there can't be duplicates. I have a username and
password field that are assigned to customers subscribing to online
products.
Any ideas? Thanks

Here's some code that will generate a password. Just enter the number of
characters you want. It includes "special characters" and a space, so
make
sure your system will handle them, or remove them from the list:

Public Function fGenRandomString(intCharCount As Integer) As String
Dim i As Integer
Dim intPos As Integer
Dim strOut As String
Dim strOne As String * 1
Dim strCharPool As String
Const strChars =
"abcdegghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789~
@!#$%^&*()+{}]["

strCharPool = strChars
strOut = ""
If Not intCharCount > Len(strChars) Then
Randomize
For i = 1 To intCharCount
intPos = Int(Len(strCharPool) * Rnd + 1)
strOne = Mid(strCharPool, intPos, 1)
strCharPool = Left(strCharPool, intPos - 1) &
Mid(strCharPool,
intPos + 1)
strOut = strOut & strOne
Next
Else
strOut = "Too Long"
End If
fGenRandomString = strOut
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
D

Douglas J. Steele

We may be talking at cross-purposes.

When you're in design mode, select the command button and look at the On
Click event in the Properties tag, you can either put a function or macro
there, or you can select [Event Procedure] from the combo box, then click on
the ellipsis (...) to the right to get to the VB Editor.

What I'm saying is that you cannot simply put the function down for the
event: you must create

Private Sub Command1_Click()


End Sub

and then put the call to fGenRandomString there.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


Antonio said:
Maybe I am missing something...Create the module, then I was thinking about
firing it in 2 different ways...one way would be to create a "Generate
Password" button or after the user tabs away from the CustomerName text box,
use the txtcompanyname value to scramble it and generate the password. In
either case, wouldn't it be an Event Procedure? Antonio

Douglas J. Steele said:
You must create an Event Procedure, and call the function in that procedure.
The function Arvin gave you cannot be used as an event.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


Antonio said:
from the button OnClick event I have fGenRandomString.

Antonio

:

How are you calling the function?

The way Arvin wrote it, you must pass the number of characters you
want
in
the string:

For instance, fGenRandomString(8) will return an 8 character string.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Arvin,

Everytime I try to reference to the function, I get an "Argument not
Optional" error message. I created a module and I am trying to
call
it
from
a cmdbutton. Thanks, Antonio

:

Hello, everyone...I just thought of something to implement in my
database...How could I have the database auto-generate a
username
and
password? Of course there can't be duplicates. I have a
username
and
password field that are assigned to customers subscribing to online
products.
Any ideas? Thanks

Here's some code that will generate a password. Just enter the number of
characters you want. It includes "special characters" and a
space,
so
make
sure your system will handle them, or remove them from the list:

Public Function fGenRandomString(intCharCount As Integer) As String
Dim i As Integer
Dim intPos As Integer
Dim strOut As String
Dim strOne As String * 1
Dim strCharPool As String
Const strChars =
"abcdegghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789~
@!#$%^&*()+{}]["

strCharPool = strChars
strOut = ""
If Not intCharCount > Len(strChars) Then
Randomize
For i = 1 To intCharCount
intPos = Int(Len(strCharPool) * Rnd + 1)
strOne = Mid(strCharPool, intPos, 1)
strCharPool = Left(strCharPool, intPos - 1) &
Mid(strCharPool,
intPos + 1)
strOut = strOut & strOne
Next
Else
strOut = "Too Long"
End If
fGenRandomString = strOut
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
A

Antonio

Douglas, that's what I did.

Douglas J. Steele said:
We may be talking at cross-purposes.

When you're in design mode, select the command button and look at the On
Click event in the Properties tag, you can either put a function or macro
there, or you can select [Event Procedure] from the combo box, then click on
the ellipsis (...) to the right to get to the VB Editor.

What I'm saying is that you cannot simply put the function down for the
event: you must create

Private Sub Command1_Click()


End Sub

and then put the call to fGenRandomString there.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


Antonio said:
Maybe I am missing something...Create the module, then I was thinking about
firing it in 2 different ways...one way would be to create a "Generate
Password" button or after the user tabs away from the CustomerName text box,
use the txtcompanyname value to scramble it and generate the password. In
either case, wouldn't it be an Event Procedure? Antonio

Douglas J. Steele said:
You must create an Event Procedure, and call the function in that procedure.
The function Arvin gave you cannot be used as an event.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


from the button OnClick event I have fGenRandomString.

Antonio

:

How are you calling the function?

The way Arvin wrote it, you must pass the number of characters you want
in
the string:

For instance, fGenRandomString(8) will return an 8 character string.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Arvin,

Everytime I try to reference to the function, I get an "Argument not
Optional" error message. I created a module and I am trying to call
it
from
a cmdbutton. Thanks, Antonio

:

Hello, everyone...I just thought of something to implement in my
database...How could I have the database auto-generate a username
and
password? Of course there can't be duplicates. I have a username
and
password field that are assigned to customers subscribing to
online
products.
Any ideas? Thanks

Here's some code that will generate a password. Just enter the
number of
characters you want. It includes "special characters" and a space,
so
make
sure your system will handle them, or remove them from the list:

Public Function fGenRandomString(intCharCount As Integer) As String
Dim i As Integer
Dim intPos As Integer
Dim strOut As String
Dim strOne As String * 1
Dim strCharPool As String
Const strChars =
"abcdegghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789~
@!#$%^&*()+{}]["

strCharPool = strChars
strOut = ""
If Not intCharCount > Len(strChars) Then
Randomize
For i = 1 To intCharCount
intPos = Int(Len(strCharPool) * Rnd + 1)
strOne = Mid(strCharPool, intPos, 1)
strCharPool = Left(strCharPool, intPos - 1) &
Mid(strCharPool,
intPos + 1)
strOut = strOut & strOne
Next
Else
strOut = "Too Long"
End If
fGenRandomString = strOut
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
A

Antonio

Douglas, it seems to be working, now...thank you...Antonio

Douglas J. Steele said:
We may be talking at cross-purposes.

When you're in design mode, select the command button and look at the On
Click event in the Properties tag, you can either put a function or macro
there, or you can select [Event Procedure] from the combo box, then click on
the ellipsis (...) to the right to get to the VB Editor.

What I'm saying is that you cannot simply put the function down for the
event: you must create

Private Sub Command1_Click()


End Sub

and then put the call to fGenRandomString there.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


Antonio said:
Maybe I am missing something...Create the module, then I was thinking about
firing it in 2 different ways...one way would be to create a "Generate
Password" button or after the user tabs away from the CustomerName text box,
use the txtcompanyname value to scramble it and generate the password. In
either case, wouldn't it be an Event Procedure? Antonio

Douglas J. Steele said:
You must create an Event Procedure, and call the function in that procedure.
The function Arvin gave you cannot be used as an event.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


from the button OnClick event I have fGenRandomString.

Antonio

:

How are you calling the function?

The way Arvin wrote it, you must pass the number of characters you want
in
the string:

For instance, fGenRandomString(8) will return an 8 character string.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Arvin,

Everytime I try to reference to the function, I get an "Argument not
Optional" error message. I created a module and I am trying to call
it
from
a cmdbutton. Thanks, Antonio

:

Hello, everyone...I just thought of something to implement in my
database...How could I have the database auto-generate a username
and
password? Of course there can't be duplicates. I have a username
and
password field that are assigned to customers subscribing to
online
products.
Any ideas? Thanks

Here's some code that will generate a password. Just enter the
number of
characters you want. It includes "special characters" and a space,
so
make
sure your system will handle them, or remove them from the list:

Public Function fGenRandomString(intCharCount As Integer) As String
Dim i As Integer
Dim intPos As Integer
Dim strOut As String
Dim strOne As String * 1
Dim strCharPool As String
Const strChars =
"abcdegghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789~
@!#$%^&*()+{}]["

strCharPool = strChars
strOut = ""
If Not intCharCount > Len(strChars) Then
Randomize
For i = 1 To intCharCount
intPos = Int(Len(strCharPool) * Rnd + 1)
strOne = Mid(strCharPool, intPos, 1)
strCharPool = Left(strCharPool, intPos - 1) &
Mid(strCharPool,
intPos + 1)
strOut = strOut & strOne
Next
Else
strOut = "Too Long"
End If
fGenRandomString = strOut
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Top