You are on page 1of 2

///encript the password

create procedure dbo.encryptpassword


(
@pclearstring varchar(100)

as

select dbo.[ufn_encryptstring](@pclearstring)
return

////decript the password

create procedure dbo.decriptpassword


(
@userid varchar(50)

as
declare @password varchar(100)
select @password=password from logon where userid=@userid
select [dbo].[ufn_decryptstring](dbo.[ufn_encryptstring](@password))
return

////implementation in .net

///to get the encripetdpasword

string pwd=encryptpassword();

private string encryptpassword()


{
string result = "";
try
{
cmd.connection = cn;
cmd.parameters.clear();
cmd.commandtext = "encryptpassword";
cmd.commandtype = commandtype.storedprocedure;
cn.open();
sqlparameter pwd1 = new sqlparameter("@pclearstring",
txtpassword.text);
cmd.parameters.add(pwd1);
result = cmd.executescalar().tostring();
}
catch (exception ex)
{
system.windows.forms.messagebox.show("connection established
exception" + ex.message);
}
finally
{
cn.close();
}
return result;
}

////decripted password based on the userid

string pwd=getpassword();

private strng getpassword()


{
string result = "";
try
{
cmd.connection = cn;
cmd.parameters.clear();
cmd.commandtext = "decriptpassword";
cmd.commandtype = commandtype.storedprocedure;
cn.open();
sqlparameter pwd1 = new sqlparameter("@userid", txtusername.text);
cmd.parameters.add(pwd1);
result = cmd.executescalar().tostring();
}
catch (exception ex)
{
system.windows.forms.messagebox.show("connection established
exception" + ex.message);
}
finally
{
cn.close();
}
return result;
}

You might also like