Hi,
You can try this one https://docs.microsoft.com/en-us/aspnet/identity/overview/migrations/migrating-an-existing-website-from-sql-membership-to-aspnet-identity
Probably truncate the AspNetUsers before migrating? As alwasy - backup your databases first!
Hi Quan,
I done th emigration successfully.
however for exsting users when I tried to login I amgetting below excpetion .
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters
I have given a try for the below Hash algorithm
HashAlgorithm hm = HashAlgorithm.Create("HMACSHA512");
DO you have any idea which alogithm type do we need to use.
Regards
Venkata Phani Kumar R
I don't think you have to use any hash algorithm in your code. A normal validate username/password should be enough. I suspect that the values you input into PasswordHash were not in correct format. Can you post one of them here?
Hi Quan,
Please find the passwordhash dp0oE8qpK7mmDpvbi4gkUBTGJFHV+3bZ5UW3+DOd83MS9cjDOT9dsVnYos8eYSjT72yNl9u/UFE5pj0kksCwRg==|1|4HHZsz6ZwJuYF2qyU9sqqA==
Expected password is Isobar123
Regards
Venkata Phani Kumar R
I think you have an extra space in the beginning, that would be the problem :)
Hi Quan,
I have cross verified. no space.
Even I have removed the passwordHash but no avail. same excpetion.
Regards
Venkata Phani kumar R
Did you follow the steps in the link I sent?
public class SQLPasswordHasher : PasswordHasher { public override string HashPassword(string password) { return base.HashPassword(password); } public override PasswordVerificationResult VerifyHashedPassword(string hashedPassword, string providedPassword) { string[] passwordProperties = hashedPassword.Split('|'); if (passwordProperties.Length != 3) { return base.VerifyHashedPassword(hashedPassword, providedPassword); } else { string passwordHash = passwordProperties[0]; int passwordformat = 1; string salt = passwordProperties[2]; if (String.Equals(EncryptPassword(providedPassword, passwordformat, salt), passwordHash, StringComparison.CurrentCultureIgnoreCase)) { return PasswordVerificationResult.SuccessRehashNeeded; } else { return PasswordVerificationResult.Failed; } } } //This is copied from the existing SQL providers and is provided only for back-compat. private string EncryptPassword(string pass, int passwordFormat, string salt) { if (passwordFormat == 0) // MembershipPasswordFormat.Clear return pass; byte[] bIn = Encoding.Unicode.GetBytes(pass); byte[] bSalt = Convert.FromBase64String(salt); byte[] bRet = null; if (passwordFormat == 1) { // MembershipPasswordFormat.Hashed HashAlgorithm hm = HashAlgorithm.Create("SHA1"); if (hm is KeyedHashAlgorithm) { KeyedHashAlgorithm kha = (KeyedHashAlgorithm)hm; if (kha.Key.Length == bSalt.Length) { kha.Key = bSalt; } else if (kha.Key.Length < bSalt.Length) { byte[] bKey = new byte[kha.Key.Length]; Buffer.BlockCopy(bSalt, 0, bKey, 0, bKey.Length); kha.Key = bKey; } else { byte[] bKey = new byte[kha.Key.Length]; for (int iter = 0; iter < bKey.Length; ) { int len = Math.Min(bSalt.Length, bKey.Length - iter); Buffer.BlockCopy(bSalt, 0, bKey, iter, len); iter += len; } kha.Key = bKey; } bRet = kha.ComputeHash(bIn); } else { byte[] bAll = new byte[bSalt.Length + bIn.Length]; Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length); Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length); bRet = hm.ComputeHash(bAll); } } return Convert.ToBase64String(bRet); }
Dear Team,
Recently I implemented owin authentication on my EPi10 project.
If possible please share migration script for usser form asp_membershiptable to AspNetUsers .
I am using the below script
INSERT INTO AspNetUsers(Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,
PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,
AccessFailedCount,UserName,NewsLetter,IsApproved,IsLockedOut,CreationDate)
SELECT aspnet_Users.UserId,aspnet_Membership.Email,'true',
(aspnet_Membership.Password+'|'+CAST(aspnet_Membership.PasswordFormat as varchar)+'|'+aspnet_Membership.PasswordSalt),
NewID(),NULL,'false','true',aspnet_Membership.LastLockoutDate,'true','0',aspnet_Users.UserName,'false','true','false',isnull(aspnet_Membership.CreateDate,GETDATE())
FROM aspnet_Users
LEFT OUTER JOIN aspnet_Membership ON aspnet_Membership.ApplicationId = aspnet_Users.ApplicationId
AND aspnet_Users.UserId = aspnet_Membership.UserId AND aspnet_Users.UserName
However I am getting the below issue
Cannot insert duplicate key row in object 'dbo.AspNetUsers' with unique index 'UserNameIndex'. The duplicate key value is (admin).
The statement has been terminated.
Regards
Venkata Phani kumar R