PHP and C# SHA256 Hashes returning different strings -


so, found question accepted answer, hopped off , tried implement necessary changes. reason though, still getting 2 different strings, , don't know i'm doing wrong. tried comment on accepted answer find help, lack reputation so. so, figured i'd ask question again (that question 2 years old, too).

let me explain i'm doing.

in php...

$intermediatesalt = md5(uniqid(rand(), true)); $salt = substr($intermediatesalt, 0, 8); $hashpassword = base64_encode( hash('sha256', $salt . hash('sha256', $password), true) ); 

the line says $hashpassword taken accepted answer question. didn't write of php, friend did. know enough programming alter code, couldn't create in php, let alone html.

after hash has been created, both hash , salt stored on database.

the c# method i'm using answer found here.

    public static string computehash(string plaintext, string salt)     {         // convert plain text byte array.         byte[] plaintextbytes = encoding.utf8.getbytes(plaintext);         byte[] saltbytes = encoding.utf8.getbytes(salt);          sha256managed hash = new sha256managed();          // compute hash value of salt.         byte[] plainhash = hash.computehash(plaintextbytes);          byte[] concat = new byte[plainhash.length + saltbytes.length];          system.buffer.blockcopy(saltbytes, 0, concat, 0, saltbytes.length);         system.buffer.blockcopy(plainhash, 0, concat, saltbytes.length, plainhash.length);          byte[] thashbytes = hash.computehash(concat);          // convert result base64-encoded string.         string hashvalue = convert.tobase64string(thashbytes);          // return result.         return hashvalue;     } 

but bizarre reason, though person asked question got s/he wanted, still getting undesired result.

this block of code loads player data compares the php generated hashed password c# generated hashed password.

        // load player based on given email         playerstructure.player newplayer = mysql.loadplayer(email);          // compute hash based on given password , retrieved salt         // then, compare hashed password on database         string hpassword = program.computehash(password, newplayer.salt);          if (newplayer.password != hpassword)         {             sendstatusmsg(index, "invalid password.");             sendstatusmsg(index, "1: " + hpassword);             sendstatusmsg(index, "2: " + newplayer.password);              return;         } 

mysql.loadplayer loads hash string , salt string database, , had use sendstatusmessage methods print strings server application takes 15 minutes load data database in debug mode. run debug exe instead, ergo no console.writeline calls. newplayer.password hashed password stored on database (the password created php). hpassword computed hash using c# method borrowed.

the salt e0071fa9 , plain-text password 'test'.

this result sendstatusmsg methods:

invalid password. 1: 3qqyvefmbn4kjjhsrq307tcdyxnmpc4k3r3udbavz8y= 2: mohrvv9c0jvpdtk28xgm3uvppuhatk2rahxd5he4zji= 

any ideas might doing incorrectly? i've stated before, literally used answer on here (borrowing code verbatim) , i'm still not getting desired result. question referenced: why isn't php sha256 hash equivalent c# sha256managed hash

because answer question linking says, hash returns hex-encoded string instead of raw bytes default. passing true third parameter override behavior outer call hash, not doing same inner call.

in fact why there 2 hashes in first place? inner hash doesn't seem serve purpose @ all.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -