Posts mit dem Label AppleScript werden angezeigt. Alle Posts anzeigen
Posts mit dem Label AppleScript werden angezeigt. Alle Posts anzeigen

Samstag, 9. April 2011

Passwort Generator

Ich brauchte mal wieder ein Passwort.

Und als ich mich in meinen Mailaccount einloggte und sah "118" fehlgeschlagene Login Versuche, habe ich mir gedacht, jetzt muß aber mal wirklich was sicheres her.

Da fiel mir ein Applescript ein, was ich vor Äonen mal in einem ehemals guten Appleforum veröffentlicht hatte. Zum Glück gibt es das Script dort noch und ich habe es mal rasch überarbeitet und erweitert.

Anmerkung: Dies ist eine erneut überarbeitete Version.
Anmerkung 2: Und nocheinmal überarbeitet. Außerdem plane ich eine JavaScript Version.

Die Vorteile des Scripts:
  1. Man kann ein simples Passwort eingeben.
  2. Man bekommt daraus immer dasselbe schwierige Passwort generiert.
  3. Dieses schwierige Passwort ist ziemlich sicher nicht zu erraten.
  4. Man kann den Generator immer wieder verwenden um sich sein schwieriges Passwort zu regenerieren. Deswegen braucht man es sich auch nirgends zu speichern.
  5. Es gibt einen "Copy" Knopf mit dem das generierte Passwort in das Clipboard kopiert werden kann um es so einfach per cmd-V zu übernehmen


--
-- Passwort Generator v0.4.2 von Skeeve
--
-- Dies AppleScript darf frei verwendet werden.
-- Es wird keinerlei Gewähr für irgendetwas übernommen.
-- Insbesondere nicht für die Sicherheit der generierten
-- Passworte!
--
-- Fragen und Anregungen bitte an
-- pwdgen.v0-4-2.skeeve et xoxy punkt net
--
on run
set version to "Passwort Generator v0.4.2"
set input to ""
repeat
set input to text returned of (display dialog "Gib Dein Passwort ein." & return & return & "Es wird dann eine sichere Variante generiert." default answer input with title version)
if input ≠ "" then exit repeat
end repeat
repeat
set input to do shell script "perl -e '
$s=substr($_=shift, 0, 2);
$s=substr(crypt($s,$s), -2);
print $s;
print substr crypt($1, $s),2 foreach (/(.{1,8})/g);
' " & quoted form of input
repeat
set choice to display dialog "Gib Dein Passwort ein, um ein weiteres sicheres zu generieren." & return & return & "• Dein sicheres Passwort lautet •" default answer input buttons {"OK", "Copy", "Cancel"} default button 1 with title version
set input to the text returned of choice
set choice to the button returned of choice
if choice is "Cancel" then return
if choice is "Copy" then
set the clipboard to the input
else
exit repeat
end if
end repeat
end repeat
end run

Samstag, 28. Februar 2009

Quoten von Shell Variablen

Heute habe ich in der AppleScript Mailinglist einen interessanten Beitrag von Mark J. Reed gelesen, der nicht nur für AppleScript Nutzer interessant ist.

Oft gibt es ja das Problem, daß man in Shell Scripten Parameter "herumreichen" muß. Mark hat das Thema "Quoting" darin schön zusammengefaßt:
Since I see lots of shell code being tossed around here, whether in do shell script strings or Terminal do scripts or scripts that invoke osascript, allow me to pass on a general tip: the best rule of thumb is to ALWAYS quote parameter expansions. Somewhat like macros in C, they are expanded *before* the shell does its normal compilation of the command (word splitting). So this:

foo="1 2 3 4"
somecommand $foo


calls "somecommand" with four arguments, not one. This is sometimes what you want, but frequently not. When I see bare $foo, I instinctively reach for the keyboard to turn it into "$foo" instead. :)

If you do want to expand something into a variable number of words, you can use an array instead of a string, especially if you find yourself trying to do yucky stuff like including quotes in the string and eval'ing the result (see above re: code generation).

foo=(1 "2 3" 4)
somecommand "${foo[@]}" # somecommand is called with three arguments


Array variables are, sadly, not POSIX-compliant. If that's an issue for you, one fallback is to use the shell's own positional parameters:

set -- 1 "2 3" 4
somecommand "$@" # calls somecommand with three arguments


..but that only works if you don't have data you care about already in the positional params.