Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write a password script?

Status
Not open for further replies.

seabreeze

Programmer
Nov 14, 2000
1
US
How do you write a mini script involving AWK to set a password that consists 7 characters [A-Za-z] generated randomly? The database output is to have the format:

UserID:password:SSN

For example, I did the following script:

awk 'BEGIN {FS=","} {
{$1=substr($1, 1, 1);
$2=substr($2, 1, 1);
$3=substr($3, 1, 1);
$10=substr($10, 6, 10); }
{ if ( $2=="" ){ n="X" } else { n=$2 } ; }
{ print $1n$3$10 ; }
}' NightFlightSite.db #the file

I'm trying to figure out about the password part. Hope you can help me out on this. Thanks!

 
Here is one way that seems to work O.K.

Test it like this:

echo "this" | rand # I called file "rand"
# Make it executable first!


nawk 'BEGIN{ alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" }

{

srand() # default seed using system time

for( i = 1 ; i<= 7 ; i++ ) {
num = 1 + int( rand() * 52 )
string = substr(alpha,num,1)
print string # delete this or comment out after testing
passwd = ( passwd string ) # concatenate chars
}

} END { print passwd }'


Hope this helps you!


flogrr
flogr@yahoo.com

 
The editor dumped the subscript in my previous
post in line:

passwd = ( passwd string )

Sorry about that!


flogrr
flogr@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top