programmation_perl
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédenteProchaine révisionLes deux révisions suivantes | ||
programmation_perl [2011/04/25 22:29] – thierry | programmation_perl [2011/10/11 21:17] – thierry | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Crypt ====== | ||
+ | |||
+ | Liens: | ||
+ | *http:// | ||
+ | *http:// | ||
+ | *http:// | ||
+ | |||
+ | But: comparer et construire des clés " | ||
+ | |||
+ | Voila: | ||
+ | # | ||
+ | | ||
+ | use strict; | ||
+ | use warnings; | ||
+ | | ||
+ | { | ||
+ | # From package: libauthen-simple-passwd-perl | ||
+ | # | ||
+ | use Authen:: | ||
+ | | ||
+ | # Où: | ||
+ | # password = mot de passe saisie (en clair) | ||
+ | # encrypted = le hash recupéré dans une base (ou fichier shadow ...) | ||
+ | # Exemple: | ||
+ | # encrypted format: | ||
+ | # $< | ||
+ | # $1$12345678$1234567890123456789012 | ||
+ | # ou $6$12345678$xxxxxxxxxxxxxxx... | ||
+ | sub check_password | ||
+ | { | ||
+ | my ( $password , $encrypted ) = @_; | ||
+ | return Authen:: | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | # Créer de la poussiere | ||
+ | # 8 caracteres aléatoires | ||
+ | | ||
+ | sub crypt_salt | ||
+ | { | ||
+ | my $salt = `( date +%s%N ; ps aux ) | md5sum | openssl base64`; | ||
+ | return substr( $salt, 0, 8 ); | ||
+ | } | ||
+ | | ||
+ | { | ||
+ | # From package: libcrypt-unixcrypt-perl | ||
+ | # | ||
+ | use Crypt:: | ||
+ | | ||
+ | sub crypt_password | ||
+ | { | ||
+ | my ( $p , $s ) = @_; | ||
+ | if ( !defined( $s ) ) { | ||
+ | # Créer la poussiere | ||
+ | $s = ' | ||
+ | } | ||
+ | return crypt($p, | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | # -------------------------------------- | ||
+ | # Chiffrement sha1 : $1$salt45678 | ||
+ | # Chiffrement sha512 : $6$salt45678 | ||
+ | # | ||
+ | # le " | ||
+ | # -------------------------------------- | ||
+ | | ||
+ | { | ||
+ | # ----------------------------- | ||
+ | # Coder un mot de passe | ||
+ | # ----------------------------- | ||
+ | | ||
+ | my $c_password = ' | ||
+ | my $e_password = crypt_password( $c_password ); | ||
+ | | ||
+ | print "Mot de passe en clair: $c_password\n"; | ||
+ | print " | ||
+ | | ||
+ | # ---------------------------- | ||
+ | # Vérifier mot de passe | ||
+ | # ---------------------------- | ||
+ | | ||
+ | print " | ||
+ | | ||
+ | # ---------------------------- | ||
+ | } | ||
+ | |||
====== Random Quantum ====== | ====== Random Quantum ====== | ||
+ | ===== Install ===== | ||
Une vraie source aléatoire en ligne: http:// | Une vraie source aléatoire en ligne: http:// | ||
Ligne 12: | Ligne 100: | ||
| | ||
- | perl Makefile.PL | + | |
- | make | + | |
- | make test | + | |
- | make install | + | |
+ | Installing / | ||
+ | Installing / | ||
+ | Writing / | ||
+ | Appending installation info to / | ||
+ | |||
+ | |||
+ | ===== Test ===== | ||
+ | |||
+ | Petit test: | ||
+ | |||
+ | # | ||
+ | |||
+ | use strict; | ||
+ | use warnings; | ||
+ | |||
+ | use Random:: | ||
+ | |||
+ | { | ||
+ | if ( my $cl = new Random:: | ||
+ | print $cl-> | ||
+ | print $cl-> | ||
+ | print $cl-> | ||
+ | print sprintf(" | ||
+ | my $h = unpack( " | ||
+ | print "At last: $h\n"; | ||
+ | } | ||
+ | } | ||
+ | Exemple: | ||
+ | $ ./test.pl | ||
+ | 196 | ||
+ | 222 | ||
+ | 3806413886 | ||
+ | 2591528E | ||
+ | At last: 508757233b068245788774a4c94cfcdc5b74 | ||
+ | |||
+ | Ca " | ||
+ | |||
+ | ===== pwgen ===== | ||
====== Ftp SSL ====== | ====== Ftp SSL ====== |
programmation_perl.txt · Dernière modification : 2011/10/11 21:19 de thierry