如何使用加密的用户名和密码登录用户 [英] how to login in user with encrypted username and password

查看:151
本文介绍了如何使用加密的用户名和密码登录用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个表单来在我的应用程序中登录我的用户,它的工作很简单,但我必须访问多个用户,这是我使用表单来创建表单来创建用户名和员工的密码。我正在使用以下代码来加密用户名和密码。

  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;



当用户登录时我使用以下代码



  string  passwordForEncryption =   sA23(^ A1& * %1!)01Ax)@ 21 @#$%^&安培; *()7984651\" ; 

string encryptedpassword = StringCipher.Encrypt(txtPWD.Text,passwordForEncryption);
string encryptedUserName = StringCipher.Encrypt(txtUserName.Text,passwordForEncryption);

实体实体= 实体();
CTP.HRMS.WebApp.EF.UserLogin login = entities.UserLogins.FirstOrDefault(x => x.Employee_Id == encryptedUserName&& x.Password == encryptedpassword);

// var login =(from u in entities.UserLogins
// 在实体中加入ee。u.Id上的雇员等于ee.Id

// 其中u.Password == encryptedpassword
// && u.UserName == encryptedUserName
/ / 选择新
// {
// FormalName = u.FormalName,
// gisuyag = ee.Address
// })。FirstOrDefault();

if (login!= null
{
MyUser.UserName = txtUserName.Text;
MyUser.Role_Id = login.Role_Id;
// MyUser.FormalName = login.FormalName; //创建包含用于显示目的的完整登录用户名的fuield
FormsAuthentication.RedirectFromLoginPage(login.Id.ToString(), true );
}

else
{

// 如果数据读取器不包含任何行,则表示用户名或密码为

// 不正确

txtUserName.Text = ;

txtPWD.Text = ;

Label3.Text = 用户名/密码不正确;
}
}



我怎么能这样做

解决方案

< blockquote>%^& *()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 ;



当用户登录时我正在使用以下代码



  string  passwordForEncryption =   sA23(^ A1& *%1)01A x)的@ 21 @# 
%^&安培;!*()7984651\" ;

string encryptedpassword = StringCipher.Encrypt(txtPWD.Text,passwordForEncryption);
string encryptedUserName = StringCipher.Encrypt(txtUserName.Text,passwordForEncryption);

实体实体= 实体();
CTP.HRMS.WebApp.EF.UserLogin login = entities.UserLogins.FirstOrDefault(x => x.Employee_Id == encryptedUserName&& x.Password == encryptedpassword);

// var login =(from u in entities.UserLogins
// 在实体中加入ee。u.Id上的雇员等于ee.Id

// 其中u.Password == encryptedpassword
// && u.UserName == encryptedUserName
/ / 选择新
// {
// FormalName = u.FormalName,
// gisuyag = ee.Address
// })。FirstOrDefault();

if (login!= null
{
MyUser.UserName = txtUserName.Text;
MyUser.Role_Id = login.Role_Id;
// MyUser.FormalName = login.FormalName; //创建包含用于显示目的的完整登录用户名的fuield
FormsAuthentication.RedirectFromLoginPage(login.Id.ToString(), true );
}

else
{

// 如果数据读取器不包含任何行,则表示用户名或密码为

// 不正确

txtUserName.Text = ;

txtPWD.Text = ;

Label3.Text = 用户名/密码不正确;
}
}



我怎么能这样做


加密信息可以是解密。您应该使用简单安全密码验证说明 [ ^ ]。


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

解决方案

%^&*()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


Encrypted information can be decrypted. You should use hashing as described in Secure Password Authentication Explained Simply[^].


这篇关于如何使用加密的用户名和密码登录用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆