Guest User

Untitled

a guest
Feb 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # Usage: read -s PASSWORD && ./bcrypt-password.pl
  3. use Crypt::Eksblowfish::Bcrypt;
  4.  
  5. # Read password and salt from environment variables
  6. $password = $ENV{PASSWORD};
  7. $salt = "lfVQ/T2N3dhFVvvPro2Hfu"
  8. $encrypted = encrypt_password($password, $salt);
  9.  
  10. # Extract bcrypt version, cost, salt, and hashed password
  11. $pattern = '(^\$2a\$\d{2}\$)(.{22})(.*)';
  12. ($e_ver_cost, $e_salt, $e_hash) = ($encrypted =~ m!$pattern!);
  13.  
  14. print "ver+cost: $e_ver_cost\tsalt: $e_salt\n";
  15. print "new hashed password\t$e_hash\n";
  16. print "old hashed password\t4753yuwaNSwLePPlA9IS4YNdjHt93Gm\n";
  17.  
  18. # Encrypt a password
  19. sub encrypt_password {
  20. my $password = shift;
  21. my $salt = shift;
  22.  
  23. # Set the cost to 10 and append a NUL
  24. my $settings = '$2a$10$'.$salt;
  25.  
  26. # Encrypt it
  27. return Crypt::Eksblowfish::Bcrypt::bcrypt($password, $settings);
  28. }
Add Comment
Please, Sign In to add comment