Outils pour utilisateurs

Outils du site


programmation_perl

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
programmation_perl [2011/04/25 22:58] thierryprogrammation_perl [2011/10/11 21:19] (Version actuelle) thierry
Ligne 1: Ligne 1:
 +====== Crypt ======
 +
 +Liens: 
 +  *http://www.jeteye.com/jetpak/e251d8b0-3b33-1029-86c1-00304880af2f/
 +  *http://search.cpan.org/~chansen/Authen-Simple-0.4/lib/Authen/Simple/Password.pm
 +  *http://search.cpan.org/~mvorl/Crypt-UnixCrypt-1.0/UnixCrypt.pm
 +
 +But: comparer et construire des clés "crypt"...
 +
 +Voila:
 +  #!/usr/bin/perl -w
 +  
 +  use strict;
 +  use warnings;
 +  
 +  {
 +  # From package: libauthen-simple-passwd-perl
 +  #
 +  use Authen::Simple::Password;
 +  
 +  # Où:
 +  # password = mot de passe saisie (en clair)
 +  # encrypted = le hash recupéré dans une base (ou fichier shadow ...)
 +  # Exemple:
 +  # encrypted format:
 +  # $<format>$<salt>$<hash>
 +  # $1$12345678$1234567890123456789012
 +  # ou $6$12345678$xxxxxxxxxxxxxxx...
 +  sub check_password
 +  {
 +    my ( $password , $encrypted ) = @_;
 +    return Authen::Simple::Password->check($password,$encrypted);
 +  }
 +  }
 +  
 +  # 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::UnixCrypt;
 +  
 +  sub crypt_password
 +  {
 +    my ( $p , $s ) = @_;
 +    if ( !defined( $s ) ) {
 +      # Créer la poussiere
 +      $s = '$6$' . crypt_salt();
 +    }
 +    return crypt($p,$s);
 +  }
 +  }
 +  
 +  # --------------------------------------
 +  # Chiffrement crypt : $1$salt45678
 +  # Chiffrement sha512 : $6$salt45678   (par defaut)
 +  #
 +  # le "salt" est créé de façon pseudo aléatoire.
 +  # --------------------------------------
 +  
 +  {
 +  # -----------------------------
 +  # Coder un mot de passe
 +  # -----------------------------
 +  
 +  my $c_password = 'M0t2P4ss3';
 +  my $e_password = crypt_password( $c_password );
 +  
 +  print "Mot de passe en clair: $c_password\n";
 +  print "Devient chiffré en sha512: $e_password\n";
 +  
 +  # ----------------------------
 +  # Vérifier mot de passe
 +  # ----------------------------
 +  
 +  print "Vérification du mot de passe : " ,  check_password( $c_password, $e_password ) ? 'OK':'**Erreur**' , "\n" ;
 +  
 +  # ----------------------------
 +  }
 +
 +Test:
 +  ./cryptdemo.pl 
 +  Mot de passe en clair: M0t2P4ss3
 +  Devient chiffré en sha512: $6$OGViYWMx$M8GagcogWG18BoF7qVpgczE9ArxrFQk5YcAnqbiBAuWni37MVYG.GDT57Isy.3Z3qTVFCMn2UbB8nFLKrQA/n1
 +  Vérification du mot de passe : OK
 +
 ====== Random Quantum ====== ====== Random Quantum ======
  
 +===== Install =====
 Une vraie source aléatoire en ligne: http://jve.linuxwall.info/blog/index.php?post/2011/03/04/Quantum-Random-Bit-Generator-Service Une vraie source aléatoire en ligne: http://jve.linuxwall.info/blog/index.php?post/2011/03/04/Quantum-Random-Bit-Generator-Service
  
Ligne 21: Ligne 115:
   Appending installation info to /usr/local/lib/perl/5.10.0/perllocal.pod   Appending installation info to /usr/local/lib/perl/5.10.0/perllocal.pod
  
 +
 +===== Test =====
  
 Petit test: Petit test:
Ligne 48: Ligne 144:
   2591528E   2591528E
   At last: 508757233b068245788774a4c94cfcdc5b74   At last: 508757233b068245788774a4c94cfcdc5b74
 +
 +Ca "lag" un peu... un problème de DNS ?
 +
 +===== pwgen =====
  
 ====== Ftp SSL ====== ====== Ftp SSL ======
programmation_perl.1303772325.txt.gz · Dernière modification : 2011/04/25 22:58 de thierry