Awesome, thanks Boris. The logic is working now.
But after the OnAuthentication method returns the UserInfo, why isn't the user authenticated as login user? It redirects back to the login form with no error, no messages, as nothing ever happen. (It usually redirects to the dashboard page if I use the default authentication).
Did I do it wrong? I copy paste the code below for your review.
Thanks,
~ Goo
public override object OnAuthentication(object userInfo, string username, string password)
{
if (userInfo != null)
{
return userInfo;
}
UserInfo user = null;
string encPass = CalculateSHA1(password, Encoding.ASCII);
CMSMembershipProvider memberProvider = new CMSMembershipProvider();
if (ValidationHelper.IsEmail(username))
{
string uName = memberProvider.GetUserNameByEmail(username);
if (encPass == memberProvider.GetPassword(uName, null))
{
user = UserInfoProvider.GetUserInfo(uName);
}
}
return user;
}
private string CalculateSHA1(string text, Encoding enc)
{
byte[] buffer = enc.GetBytes(text);
SHA1CryptoServiceProvider cryptoTransformSHA1 = new SHA1CryptoServiceProvider();
string hash = BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
return hash;
}