]>
jfr.im git - irc/SurrealServices/srsv.git/blob - tags/0.4.3.1-pre2/SrSv/Upgrade/HashPass.pm
1 package SrSv
::Upgrade
::HashPass
;
6 BEGIN { our @EXPORT = qw(hash_all_passwords) }
8 use SrSv
::Hash
::SaltedHash
;
9 use SrSv
::Hash
::Passwords
qw( hash_pass validate_pass is_hashed );
10 use SrSv
::MySQL
'$dbh';
11 use SrSv
::Process
::Init
;
12 use SrSv
::Conf
'main';
14 my ($get_nicks, $replace_pass);
17 $get_nicks = $dbh->prepare("SELECT nick, id, pass FROM nickreg ORDER BY id");
18 $replace_pass = $dbh->prepare("UPDATE nickreg SET pass=? WHERE id=?");
21 sub hash_all_passwords
() {
22 return unless $main_conf{'hashed-passwords'};
24 print "Updating passwords...\n";
26 $dbh->do("LOCK TABLES nickreg WRITE");
28 $get_nicks->execute();
29 while (my ($nick, $nrid, $pass) = $get_nicks->fetchrow_array() ) {
30 next if is_hashed
($pass);
32 my $hashedPass = hash_pass
($pass);
34 #print STDOUT "$nick, $nrid, $pass, $hashedPass\n";
35 #print STDOUT (validate_pass($hashedPass, $pass) ? "hash is valid" : "hash is not valid" )."\n";
36 #print STDOUT " ----------------- \n";
37 validate_pass
($hashedPass, $pass) or die "Internal error while converting password ($pass, $hashedPass)";
39 $replace_pass->execute($hashedPass, $nrid);
42 $dbh->do("UNLOCK TABLES");