Saturday, August 8, 2009

Is Blood Donation A Reason For Late Mentrual?

Script Tip # 10: Password generator for Mac OS X and Linux

For all the more once a new password will need a small password generator pays for the command line. On Linux, this is a short enough one-liners, with MacOS X Leopard are a few lines longer necessary (at least until the current Version 10.5.8), because a strange error on Mac OS X Leopard has to be bypassed.
Linux

First, the basic part of the example Linux. First urandom is generated with a (pseudo) random number stream with

tr
a meaningful sign (here: on the keyboard easily be input) is limited and truncated by
head to the desired length.
tr-dc "[: graph:]"

The output character set can be controlled as follows: [: alnum:] letters and numbers only

[: alpha:] all letters
 < /dev/urandom | head -c10
[: digit:] only numbers

[: graph:] only durckbare characters, except space
  • [: lower:] all lower case
  • [: upper:] all caps
  • [: xdigit:] Only hexadecimal characters
  • These are only useful for passwords parameter. Who else might need, so read it with
  • tr.
  • MacOS X

to use under MacOS X Leopard, the one-liners from the Linux section, you get an error message that goes back to a bug in Leopard:

#: ~> tr-dc "[: graph:] "
This error message appears if the LOCALE LC_ALL has a value other than C (on a system, this is mostly Deuscher en_US.UTF-8). To work around this bug we must therefore adjust the variable LC_ALL accordingly and if you work longer in a script to its original value after reset:
# / usr / bin / bash # env lc = $ LC_ALL LC_ALL = C tr -! dc "[: graph:]"

This script gives the same result as the one-liner on Linux, a ten-digit string.

 < /dev/urandom | head -c10
head: can't combine line and byte counts
tr: Illegal byte sequence

Mixed

 < /dev/urandom | head -c10
LC_ALL=$lc

Man, this script can do even aufhübschen. Replacing

head-c10
by
head-c $ {1: -10} the password length can be easily controlled by delivery of a value. If nothing is passed, default is a ten-digit output. A further improvement could be that the output immediately and directly to the clipboard (see # script Tip 7: Data exchange between clipboard and terminal
) is written. This is handy if you often need passwords while surfing. On Linux this is done with
xclip

under MacOS X with pbcopy : tr-dc "[: graph:]" tr-dc "[: graph:]"

Zum Abschluss noch eine runde, komplette Lösung für MacOS X.
 
< /dev/urandom | head -c ${1:-10} | xclip
Für Macianer die gar nicht gerne mit dem Terminal arbeiten, gibt es die Möglichkeit den Passwortgenerator in die Menüleiste zu integrieren (vgl.
 Skripttipp #1: Bashskripte in die Menüzeile des Finders einbinden < /dev/urandom | head -c ${1:-10} | pbcopy
). Die einfachste Möglichkeit ist, ein Alias auf das Skript (oder auch das Skript selber) unter »~/Library/Scripts/« abzulegen. Bei dieser Variante können dem Skriptaufruf keine Parameter übergeben werden. Daher ist es besser, ein kleines AppleSkript zu schreiben, welches das Bashskript ggf. mit entsprechenden Parametern aufruft.

Eine Komplette Lösung, also Passwortgenerator . In the menu bar and an alias in bashrc point with different parameters on the bash script:

The script


# / usr / bin / env bash # # File Name Password Generator # Author Globenaut # Created 08/08/2009 #! Description amended 08.08.2009 # Generates pseudo-random strings for passwords. # Parameter $ 1: length of the string pb = 0 character set = '[: graph:]' while getopts': abcghkxz 'button do case "$ switch" in a) character set =' [: alnum :]';; b) character set = '[: alpha :]';; g) character set =' [: upper :]';; k) character set = '[: lower :]';; x) character set =' [: xdigit :]';; z) character set = '[: digit :]';; c) pb = 1;; \\? ) Echo 'termination because of unknown switch: -' $ OPTARG; exit;; esac done shift $ ((OPTIND - 1)) lc = $ LC_ALL LC_ALL = C pw = `tr-dc '[: graph:]"

The apple script
 < /dev/urandom | head -c ${1:-10}`
LC_ALL=$lc
if [ $pb == 1 ]; then
echo -n $pw | pbcopy
else
echo $pw
fi

exit 0
########## Weitere Erl?uterungen zum Skript ##########
# Schalter:
# -a Alphanumerische Zeichen [:alnum:].
# -b Nur Buchstaben [:alpha:].
# -c Wenn vorhanden wird die Zeichenfolge in die Zwischenablage geschrieben, ansonsten auf stdout ausgegeben.
# -g Nur Gro?buchstaben [:upper:].
# -h Ruft diese Hilfe auf.
# -k Nur Kleinbuchstaben '[:lower:].
# -x Nur hexadezimale Zeichen [:xdigit:].
# -z Nur Ziffern [:digit:].

tell current application do shell script "~ / bin / password-generator-c 10" end tell

The path to the script must possibly be adapted and it must be in "~ / Library / Scripts / "will be saved. Jetzt steht der Passwortgenerator in allen Programmen in der Menüzeile zur Verfügung (sofern das Skriptmenü aktiviert ist, vgl.
Skripttipp #1 ). Bei Anklicken der Menüzeile wird eine 10stellige pseudozufällige Zeichenfolge in die Zwischenablage geschrieben, gebrauchsfertig zum Einsetzen in Webformulare. Achtung: Die Zeichenfolge ggf. notieren, da Passwortfelder Selbige nicht anzeigen und sie nicht reproduzierbar ist!

 Das Alias 




alias pw='Passwortgenerator 20'


Bei Aufruf von pw im Terminal wird eine 20stellige Zeichenfolge auf der Kommandozeile ausgegeben.



Darüberhinaus hat Add to this the possibility of the bash script with any parameters menu:
 #: ~> Password Generator 35 #: ~> S, / Eqzd) GDGHeSc %:]/# tQaUXr {&`~? rFgO #: ~> Password Generator-c 40 

The script is set so that output for the string does not break, if it is written to the clipboard (thus

echo-n $
pw), for output to the command line does.

 

0 comments:

Post a Comment