sql - Converting Plain Password to EF Asp.Net Identity PasswordHash -
i have project need migrate lot of users has password in plain text new database hash password.
the new system use entity framework , needs authenticated asp.net identity framework.
i found can generate in c# correct hashed password entity framework can read without problem.
public static string hashpassword(string password) { byte[] salt; byte[] buffer2; using (var bytes = new rfc2898derivebytes(password, 0x10, 0x3e8)) { salt = bytes.salt; buffer2 = bytes.getbytes(0x20); } byte[] dst = new byte[0x31]; buffer.blockcopy(salt, 0, dst, 1, 0x10); buffer.blockcopy(buffer2, 0, dst, 0x11, 0x20); return convert.tobase64string(dst); }
is there similar in sql use within insert statement form select other table?
not built in, hashing cpu intensive , operation want avoid on db server, realize migration not normal operation though. solution depends bit on why want run in sql.
if it's because of simplicity @ in question is there sql implementation of pbkdf2?
if it's because of performance consider building small .net migrator , use bulk inserting/updating. example https://github.com/mikaeleliasson/entityframework.utilities#batch-update-entities read userid , plain text password select. hash in .net , update database in 1 bulk @ on 100k updates / second.
now 2 slight warnings make sure don't end plain text passwords in transaction log. preferebly doing hashing in source database before ends in new one. otherwise it's possible clear transaction log after initial import how clear sql server transaction log?
instead of writing hashing method can use passwordhasher asp.net identity using default. in turn using rfc2898derivebytes. see answer https://stackoverflow.com/a/21496255/507279
Comments
Post a Comment