Manual talk:$wgPasswordSalt
Add topicAppearance
Latest comment: 10 years ago by Xiong in topic Creating the Hash
Creating the Hash
[edit]I rm all the sample code because it's just plain wrong. Blatantly, it does not generate the stuff demanded at Manual:User_table#user_password.
I have succeeded in doing what's required but I'm very weak in PHP and I don't cotton to cramming that much tricky stuff into a SQL query. So I did it in Perl. This is for $wgPasswordSalt=true (default).
use Digest::MD5 'md5_hex';
my $salt = sprintf "%08x", ( int( rand() * 2**31 ) );
my $hashed = md5_hex( $password );
$hashed = md5_hex( $salt . q{-} . $hashed );
$hashed = q{:B:} . $salt . q(:) . $hashed ;