Sajid Hussain

Sajid Hussain

  • NA
  • 346
  • 48.6k

how to login in user with encrypted username and password

May 9 2015 4:11 AM
i have created a form to login my user in my application,its work fine for simple set up,but i have to access to multiple user that is way i am using a form to create a form to make a user name and password for the employee. i am using following code to encrypt user name and password.
 string passwordForEncryption = "sA23(^A1&*%1)01Ax)@!21!@#$%^&*()7984651";
 string encryptedpassword = StringCipher.Encrypt(ddlRollNo.Text, passwordForEncryption);
 string encryptedUserName = StringCipher.Encrypt(txtPassword.Text, passwordForEncryption);
 CTP.HRMS.Business.UserLogin ulogin = new Business.UserLogin();
 ulogin.Role_Id = SafeConvert.ToByte(ddlRole.SelectedValue);
 ulogin.Employee_Id = encryptedUserName;
 ulogin.Password = encryptedpassword;
and when user login i am using following code
                string passwordForEncryption = "sA23(^A1&*%1)01Ax)@!21!@#$%^&*()7984651"; 
string encryptedpassword = StringCipher.Encrypt(txtPWD.Text, passwordForEncryption);
 string encryptedUserName = StringCipher.Encrypt(txtUserName.Text, passwordForEncryption);
Entities entities = new Entities();
CTP.HRMS.WebApp.EF.UserLogin login = entities.UserLogins.FirstOrDefault(x =>x.Employee_Id==encryptedUserName && x.Password == encryptedpassword);
 //var login = (from u in entities.UserLogins
// join ee in entities.Employees on u.Id equals ee.Id
// where u.Password == encryptedpassword
// && u.UserName == encryptedUserName
// select new
// {
// FormalName = u.FormalName,
// gisuyag = ee.Address
// }).FirstOrDefault();
if (login != null)
{ MyUser.UserName = txtUserName.Text;
MyUser.Role_Id = login.Role_Id;
// MyUser.FormalName = login.FormalName;
 //Create A fuield that contains full Name of logged in user for diaplay purpose

FormsAuthentication.RedirectFromLoginPage(login.Id.ToString(), true);
} else
{
//if data reader doesn’t contains any row, it means user name or password is
//incorrect txtUserName.Text = "";
txtPWD.Text = "";
Label3.Text = "User Name/Password not correct";
} }

how i can i do this

Answers (2)