Generating random default in access field

A

Andrew Turner

Can anyone tell me what to set the default as in an access database in order
to store a random password, preferably made up of text and numbers?

Many thanks
Andrew Turner
 
A

Al Campagna

Andrew,
See Rnd Function in Help.
You don't indicate what format the password will take. I'll use the
following format
TTTNNN (ex. GFS196, or UWA712)
To generate text, you'll need to handle each letter seperately, by
generating a number between 65 and 90, and then using that number to
generate an Ascii character. Asc(65) = "A" Asc(90) = "Z"

Dim MyText1 as Integer, MyText2 as Integer, MyText3 as Integer

MyText1 = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

Do that 3 times, for each MyText variable, and concatenate the results.
= MyText1 & MyText2 & MyText3

Then use the Rnd function to generate a number between 100 and 999 and
concatenate that onto the text portion.

--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html
"Find a job that you love... and you'll never work a day in your life."
 
D

Douglas J. Steele

You don't use strong passwords? <g>

You could easily change that to, say TtttNNN so that it's Gfs196 or Uwa712
by adding additional code for also generate numbers between 97 and 122 (
Asc("a") and Asc("z")) to generate the lower case letters. You could even go
further to generate some special characters (!@#$%^&*) and include spaces.
 
A

Andrew Turner

OK, this is a little more complicated than I was hoping for but at least I
can see it might be possible.

Very simply (because am am not so bright!), using a table in access in
design view mode, what should I type in as the dafault if I want to generate
a random string of both letters and numbers.

Many thanks
Andrew Turner
 
J

James A. Fortune

Andrew said:
Can anyone tell me what to set the default as in an access database in order
to store a random password, preferably made up of text and numbers?

Many thanks
Andrew Turner

tblIntegers
ID AutoNumber
theInt Long
ID theInt
1 1
2 2
3 3

qryRandomPasswords:
SELECT ID, Rnd(ID)*10^9 AS Seed,
"abcedefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?@!#$%^&*()_"
AS Characters, Seed Mod 74+1 AS Pos1, Mid([Characters],[Pos1],1) AS
Result, [Result] & [Result] & [Result] & [Result] & [Result] & [Result]
& [Result] & [Result] & [Result] & [Result] AS RandomPassword FROM
tblIntegers;

!qryRandomPasswords:
ID Seed Characters Pos1 Result RandomPassword
1 179401874.542236 abc... 24 G MKKSnHgCoo
2 52891194.8204041 abc... 18 D GX4BLo3dLj
3 684617638.587952 abc... 32 e ueBq&*yPtC

That uses 10 characters, but it's easy to change it to 14 characters.
Since clicking on a record in the query can change values or display
strangely, it may be better to run a Make Table query similar to what I
did here if you want to generate a list of random passwords:

http://groups.google.com/group/comp.databases.ms-access/msg/74ee550e77af8209

To get this to fill in on a form control's control source, use a table
with one record instead of three and call a public function where the
SQL string above is evaluated. Put an equal sign before the function
call in the control source.

James A. Fortune
(e-mail address removed)
 

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