decrypting a password for use with the login control V2
Posted on 2006-04-19
I'm using the login control in conjunction with the createuserwizard control in V2. I've created a user through the wizard control and now I want to log in under that user. I've checked the DB and the user is being added in the membership table under the adventureworks DB.
I would like to get some sample code that would show me some methods of how to do this.
my current code is shown below. however I suspect in order to read the password from the membership table I have to decrypt it first before it can be read.
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
bool Authenticated = false;
Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Authenticated;
if (Authenticated == true)
private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
bool boolReturnValue = false;
string strConnection = "server=comp2-28;Data Source=comp2-28;initial catalog=AdventureWorks;user id=se;password=Zaq!xsw2";
SqlConnection Connection = new SqlConnection(strConnection);
String strSQL = "Select * From aspnet_membership where username = UserName";
SqlCommand command = new SqlCommand(strSQL, Connection);
Dr = command.ExecuteReader();
if ((UserName == Dr["username"].ToString()) & (Password == Dr["PasswordAnswer"].ToString()))
boolReturnValue = true;
I haven't started implementing this yet because i suspect the password vairable from login1 and the encrypted passwordanswer in the sql won't match due to encryption. I've found the decrptpassword method but little examples on how to use it for C#.
public override string GetPassword (
my question is; does the password in sql need to be decrypted first before it can be compared to the password in the login1 control, if so how is the decryptpassword method used to do so? The select statement I suspect would return the encrypted value which would not compare to the string value; if ((UserName == Dr["username"].ToString()) & (Password == Dr["PasswordAnswer"].ToString()))
How could I change this to work. any suggestions are greatly appreciated.