| Author |
Message |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Thu 29 Sep 2011, 02:03 Post subject:
password generator |
|
This generates a 12 char password using numbers/symbols/large and small cap letters.
| Code: |
#!/bin/sh
## Generates Passwords
x="0" # length of password
flag="0" # limit number of symbols
cflag="0" # limit number of digits
while ((x < 12)); do
var="$(echo $RANDOM | cut -c 1-2)"
## get symbols
if [ "$flag" -lt "2" ]; then
if [ "$var" -lt 27 -a "$var" -gt 22 ]; then
printf "\x${var}"
flag=$((flag + 1))
x=$((x + 1))
fi
fi
## get numbers
if [ "$cflag" -lt "3" ]; then
if [ "$var" -lt 40 -a "$var" -gt 30 ]; then
printf "\x${var}"
cflag=$((cflag + 1))
x=$((x + 1))
fi
fi
## get letters
if [ "$var" -gt 40 -a "$var" -lt 80 ]; then
printf "\x${var}"
x=$((x + 1))
fi
done
echo "
"
|
| Code: |
/mnt/sda2/Desktop $ password-generate
BU7f!y1&&2wC
|
Last edited by jpeps on Thu 29 Sep 2011, 18:27; edited 2 times in total
|
|
Back to top
|
|
 |
GatorDog

Joined: 12 Sep 2006 Posts: 136
|
Posted: Thu 29 Sep 2011, 05:03 Post subject:
|
|
Hi jpeps,
Very possible I'm missing something but if I'm reading you code right it won't be generating -
0 (zero)
J - O and Z (caps)
j - o and z (lower case)
For zero change
if [ "$var" -lt 40 -a "$var" -gt 30 ]; then
to
if [ "$var" -lt 40 -a "$var" -ge 30 ]; then
The 2-digit random numbers generated are decimal. | Code: | | var="$(echo $RANDOM | cut -c 1-2)" |
The hex digits A-F won't be generated and so the above mentioned letters won't be selected for duty.
---------------------
This will generate a 2-digit (1-byte) hex number: | Code: | | var=$(2>/dev/null dd if=/dev/urandom bs=1 count=1 |od -An -tx1) |
But it might be better to generate a number less than 127, do the if/then
testing in decimal, then convert the selected number to hex.
I think this will generate a random number less than 127 | Code: | | var=$(($RANDOM % 127)) |
Convert var to a hex number- | Code: | | var=$(printf "%x" $var) |
Then again maybe I'm full of it and should leave well enough alone.
gDog
|
|
Back to top
|
|
 |
vovchik

Joined: 23 Oct 2006 Posts: 1231 Location: Ukraine
|
Posted: Thu 29 Sep 2011, 05:52 Post subject:
|
|
Hi guys,
I did something a bit similar once (but in BaCon) and it is here: http://208.109.22.214/puppy/viewtopic.php?p=400744&sid=19bd2e6d22077c2caad901ef15d93b82
With kind regards,
vovchik
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Thu 29 Sep 2011, 11:45 Post subject:
|
|
| GatorDog wrote: |
The 2-digit random numbers generated are decimal. | Code: | | var="$(echo $RANDOM | cut -c 1-2)" |
The hex digits A-F won't be generated and so the above mentioned letters won't be selected for duty. |
The code for letters is below it, and gets large caps/small caps. Large caps are 41-59 (z excluded). You can see them in the sample printout.
I didn't bother z, (z is "5a", so I'd have to include a special line of code for it since the other letters are simple digits). Sometimes 0's can confused with O's, so I didn't bother with that either. There are also symbols I didn't include, but they could be added with additional code. Some get tricky when sending ftp, though, due to escape issues.
Hi vovchik....I'm too paranoid to use a password that I can read
|
|
Back to top
|
|
 |
GatorDog

Joined: 12 Sep 2006 Posts: 136
|
Posted: Thu 29 Sep 2011, 17:25 Post subject:
|
|
| Code: | | Large caps are 41-59 |
Yes, but codes 41-59 are the hex codes. (41,42,43,44,45,46,47,48,49,4A,4B,4C,4D,4F, 50,51,52,53,54,55,56,57,58,59) for A thru Z
| Code: | | var="$(echo $RANDOM | cut -c 1-2)" |
generates the decimal numbers 10-99; so the hex numbers 4A 4B 4C 4D 4E 4F (J-O) and 6A 6B 6C 6D 6E 6F (j-o) won't be generated.
| Quote: | You can see them in the sample printout.
BU7f!y1&&2wC | There are no J-O or j-o. There are the letters before and after, but none of those.
With the script as is, I don't think you'll ever see those characters.
Again I could be missing something; but I ran the script a number of times
and those letters didn't appear. (maybe a bad $RANDOM )
On the other hand, there is that Eastern philosophy that just because
something has never happened does not mean it will never happen
I mod'ed your code a little. This will include the upper/lower JKLMNO and Z
| Code: | #!/bin/sh
## Generates Passwords
x="0" # length of password
flag="0" # limit number of symbols
cflag="0" # limit number of digits
psword_len=12
lower=32
upper=123
range=$(($upper - $lower))
print_chr (){
var_hex=$(printf "%x" $var) #covert decimal to hex number
printf "\x${var_hex}"
x=$((x + 1))
}
while ((x < $psword_len)); do
var=$((($RANDOM % $range) + $lower))
## get symbols
if [ "$flag" -lt 3 -a "$var" -lt 39 -a "$var" -gt 32 ]; then
print_chr
flag=$((flag + 1))
continue
fi
## get numbers
if [ "$cflag" -lt 3 -a "$var" -lt 58 -a "$var" -gt 47 ]; then
print_chr
cflag=$((cflag + 1))
continue
fi
## get upper case letters
if [ "$var" -gt 64 -a "$var" -lt 91 ]; then
print_chr
continue
fi
## get lower case letters
if [ "$var" -gt 97 -a "$var" -lt 123 ]; then
print_chr
fi
done
echo " "
| !PCbpd8Nk6qm
I'd be a little leery of using most of those symbols in a password. Quotes (") for instance; but guess it depends on what your needs are.
gDog
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Thu 29 Sep 2011, 17:53 Post subject:
|
|
| GatorDog wrote: |
generates the decimal numbers 10-99; so the hex numbers 4A 4B 4C 4D 4E 4F (J-O) and 6A 6B 6C 6D 6E 6F (j-o) won't be generated. |
Right...I didn't bother with non-digit hex numbers....which goes beyond my purpose. You edited the post I responded to re: (A-F).
re: "quotes" Think I'll edit that out..so
| Code: |
if [ "$var" -lt 27 -a "$var" -gt 22 ]
|
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Thu 29 Sep 2011, 20:36 Post subject:
|
|
GatorDog raises an interesting point regarding use of hex. In his revision, he first converts number to hex, instead of trying to read hex directly. That prevents the following error:
| Code: |
printf "\x106"
6
printf "%x" 106
6a
printf "\x6a"
j
|
|
|
Back to top
|
|
 |
GatorDog

Joined: 12 Sep 2006 Posts: 136
|
Posted: Thu 29 Sep 2011, 22:43 Post subject:
|
|
| Quote: | | Right...I didn't bother with non-digit hex numbers....which goes beyond my purpose. You edited the post I responded to re: (A-F). |
Yep, sometimes going to the nth degree gets to be overkill. I'll have to check back up through this thread and see which post was edited.
|
|
Back to top
|
|
 |
GatorDog

Joined: 12 Sep 2006 Posts: 136
|
Posted: Fri 30 Sep 2011, 01:24 Post subject:
|
|
Just for fun, here's a Q & D Bacon version-
| Code: | Master_1$ = "_ - + . A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
Master_2$ = " 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z"
Master$ = CONCAT$(Master_1$, Master_2$)
SPLIT Master$ BY " " TO Chr$ SIZE Count
Pw$ = "[{<(@^&*)>}]"
FOR Index = 1 TO LEN(Pw$)
Pw$ = REPLACE$(Pw$, MID$(Pw$, Index, 1), Chr$[RANDOM(Count + 1)])
NEXT Index
PRINT Pw$ |
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Wed 07 Dec 2011, 06:00 Post subject:
|
|
Decided to create a gtkdialog front-end, which incorporates the above ideas in addition to making sure the end result has numbers, symbols, and letters. Generates to editable entry box
front end:
| Code: |
#!/bin/sh
## Front end for password-generator.sh. jpeps 12/11
touch /tmp/pass
export GEN="/usr/local/passgen/password-generate.sh"
Generate() {
"$GEN" >/tmp/pass
## check for symbols & numbers
while ([ ! "$var" ]); do
# check for numbers
var="$(cat /tmp/pass | grep "[0-9]")"
## check for sympbols
[ "$var" ] && var="$(cat /tmp/pass | sed 's/[0-9a-Z]//g')"
## if no sybols and numbers, re-generate
[ "$var" ] || "$GEN" >/tmp/pass
done
}
export -f Generate
export MAIN_DIALOG='
<window title="Random Password" default-width="210">
<vbox>
<entry>
<variable>ENTRY</variable>
<input file>/tmp/pass</input>
</entry>
<hbox>
<button tooltip-text="Generate new password" space-expand="true">
<input file icon="gexec"></input>
<label>" Generate "</label>
<action>Generate</action>
<action>refresh:ENTRY</action>
</button>
<button cancel></button>
</hbox>
</vbox>
</window>
'
gtkdialog --program=MAIN_DIALOG
rm /tmp/pass
|
| Description |
|
| Filesize |
9.03 KB |
| Viewed |
367 Time(s) |

|
| Description |
Menu/System|Password Generator exec: "pass-gen"
|

Download |
| Filename |
passgen-1.0.pet |
| Filesize |
1.41 KB |
| Downloaded |
105 Time(s) |
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Thu 08 Dec 2011, 06:28 Post subject:
|
|
| Code: | | tr -cd [0-z] </dev/urandom |head -c ${PASSWORDLENGTH:-10} |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2421
|
Posted: Thu 08 Dec 2011, 12:25 Post subject:
|
|
| technosaurus wrote: | | Code: | | tr -cd [0-z] </dev/urandom |head -c ${PASSWORDLENGTH:-10} |
|
Seems to work better:
| Code: |
tr -cd '0-z' </dev/urandom |head -c ${PASSWORDLENGTH:-10}
|
For some reason, this tended to hang up from within a program, requiring me to kill the process.
|
|
Back to top
|
|
 |
|