I am working with a application when user can login in the program by typing their information. Passwords are stored in table as encrypted. But when i try to login using this password it doesn't work.
For encrypting data I use this stored procedure
ALTER procedure [dbo].[inn]
@use varchar (50) = null,
@ins varchar (50) = null
AS
INSERT INTO [kole].[dbo].[koll]
([Userr]
,[ins])
VALUES
(@use,
((EncryptByPassPhrase('8', @ins)))
And for decrypte I use this stored Procedure
ALTER procedure [dbo].[sle]
@Use varchar (50) = null,
@ins varchar (50) = null
AS
SELECT Userr,CONVERT(varchar(50),DECRYPTBYPASSPHRASE ('8',ins)) as Password
FROM [kole].[dbo].[koll]
where Userr = @Use and ins = @ins
GO
In c# I use this code for calling data, and log in into program.
private void btn_Click(object sender, RoutedEventArgs e)
{
SqlConnection conn = new SqlConnection("Server = localhost;Database = kole; Integrated Security = true");
SqlCommand cmd = new SqlCommand("sle", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Userr", txt.Text);
cmd.Parameters.AddWithValue("@ins", psw.Password);
conn.Open();
SqlDataAdapter adapt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapt.Fill(ds);
conn.Close();
int count = ds.Tables[0].Rows.Count;
if (count == 0)
{
MessageBox.Show("This user don't exist");
SystemSounds.Hand.Play();
txt.Text = "";
psw.Password = "";
}
else if (count == 1)
{
MessageBox.Show("Granted!");
SystemSounds.Asterisk.Play();
conn.Open();
}
How can I decrypt the password in correct way , to use for login into program. Thanks
Aucun commentaire:
Enregistrer un commentaire