如何登录 - 密码和用户名错误 [英] How to login - Wrong password and username

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

问题描述

M使用asp登录控件。这是我的代码

M using asp login control . here is my code

<asp:Login ID="loginDetails"
                                UserNameRequiredErrorMessage="Enter user name" runat="server"
                                PasswordRecoveryText="Forgot Password?"
                                PasswordRecoveryUrl="~/ForgotPassword.aspx" FailureText="The user name or password is incorrect."
                                OnAuthenticate="login_Authenticate" ForeColor="Black" BackColor="#F7F7DE" BorderColor="#CCCC99"
                                BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"
                                Font-Size="10pt" DisplayRememberMe="False" RememberMeText="">
                                <TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" />

                            </asp:Login>





=================== ============================



这是我的login_Authenticate





===============================================

Here is my login_Authenticate

protected void login_Authenticate(object sender, AuthenticateEventArgs e)
    {       
        string newUsername1 = loginDetails.UserName.TrimStart(' ');
        string newUsername2 = newUsername1.TrimEnd(' ');
        if (!IsPostBack)
        {            
                Session["x"] = txtUsename.Text;
                DataTable dt = new DataTable();
                dt = DLL.GetPersonId(txtUsename.Text, txtPassword.Text);
                Response.Redirect("Default.aspx");           
        }
        Session["Username"] = newUsername2.ToLower();
        if (Membership.ValidateUser(newUsername2.ToLower(), loginDetails.Password))
        {          
            e.Authenticated = false;
            if (e.Authenticated == true)
            {
                DataTable dt = DLL.GetPersonId(newUsername2.ToLower(), loginDetails.Password);
                if (dt.Rows.Count > 0)
                {
                    Session["Admin_Number"] = dt.Rows[0]["admin_Number"].ToString();
                }
            }
        }
        else
        {
            e.Authenticated = false;
        }
    }





================= ===================================

这是我的GetPerson方法





====================================================
This is my GetPerson method

public DataTable GetPersonId(string username, string password)
       {
           DataTable dataTable = new DataTable();

           using (SqlConnection con = new SqlConnection(ConnString))
           {
               SqlCommand cmd = con.CreateCommand();
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.CommandText = "GetUserID";



               cmd.Parameters.Add(new SqlParameter("@Admin_Username", SqlDbType.NVarChar, 10));
               cmd.Parameters["@Admin_Username"].Value = username;
               cmd.Parameters.Add(new SqlParameter("@Admin_password", SqlDbType.NVarChar, 10));
               cmd.Parameters["@Admin_Password"].Value = password;


               SqlDataAdapter da = new SqlDataAdapter(cmd);

               try
               {
                   con.Open();
                   da.Fill(dataTable);
               }
               catch (SqlException ex)
               {
                   throw new ApplicationException(ex.Message);
                   throw new ApplicationException("Error reading from database.");
               }
               return dataTable;
       }



当我尝试输入我的用户名和密码时,它总是说错误的用户名和密码



请帮助!!!


When i try to put my username and password it always says wrong username and password

Please help!!!

推荐答案

e.Authenticated = false;
if (e.Authenticated == true)





您有条件,并且对于这两种结果,您将身份验证设置为false。这不会有帮助!



另外,我认为你想要之后返回 > Response.Redirect ,虽然您正在尝试做那些我不明白。



You've got a condition and for both outcomes you set the authentication to false. That's not going to help!

Also, I think you want a return after the Response.Redirect, although quite what you're trying to do there I don't understand.


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

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