I'm trying to create a registration page for an SQL server, and I have some problems when it comes to the login section. The column Passphrase is set to dataType Binary(20). When a user registers an account from my form it enters their password in the Passphrase column as .
insertUser.Parameters.AddWithValue("@Passphrase", System.Text.Encoding.Default.GetBytes(TextBoxPass.Text));
When I create a Password using the default stored procedure for creating accounts it sets the password in the Passphrase column as "NULL".
ALTER FUNCTION [dbo].[FN_HashPassphrase2](
@vchPassphrase varchar(12),
@intAccountID int
)
RETURNS binary(20)
AS
BEGIN
RETURN (
HASHBYTES('md5',@vchPassphrase)
);
END
When I try to log into an account that was created with the registration page I get password mismatch.
My question is this...
When someone enters their account info into the login fields, how can I convert the back into varchar(12) when the login button is clicked?
Here is my button click
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegDNMembershipConnectionString"].ConnectionString);
con.Open();
string cmdStr = "select count(*) from Accounts where AccountName='" + TextBox1.Text + "'";
SqlCommand Checkuser = new SqlCommand(cmdStr, con);
int temp = Convert.ToInt32(Checkuser.ExecuteScalar().ToString());
if (temp == 1)
{
string cmdStr2="Select Passphrase from Accounts where AccountName='" + TextBox1.Text + "'";
SqlCommand pass=new SqlCommand(cmdStr2, con);
string password=pass.ExecuteScalar().ToString();
con.Close();