0

フォーム認証を使用しています。ここではログイン コントロールを使用しており、(login.cs) コントロールでは、次のメソッドを呼び出してユーザーを検証しています。ここでは、ユーザー名とパスワードの両方にローカル名を使用しています。データベースに接続して、ユーザー名とパスワードを取得できるようにします。

private bool Authenticateme(string username, string password, bool remberusername)
{
    String localusername = "username";
    String localpassword = "amar";
    if (username.Equals(localusername) && password.Equals(localpassword))
    {
        return true;
    }
    else
    {
        return false;
    }
}
4

3 に答える 3

2

MemberShip と Role Providers を使用できます

于 2012-08-04T06:23:19.187 に答える
0

OnAuthenticate次のように追加して実装する必要があります。

<asp:Login OnAuthenticate="AuthenticateEventHandler" />

このように.csファイルにイベントハンドラーを追加します

private void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
    bool Authenticated = false;
    Authenticated = SiteSpecificAuthenticationMethod(Login1.UserName, Login1.Password);

    e.Authenticated = Authenticated;
}

SiteSpecificAuthenticationMethodデータベースに対してユーザーを検証する実装。

参照リンクは次のとおりです。

  1. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.authenticate.aspx
  2. http://forums.asp.net/t/1403132.aspx

さらにサポートが必要な場合はお知らせください。

于 2012-08-04T06:25:58.517 に答える
-1

以下を試して、フィールドのユーザー名とパスワードを使用して SQL Server データベースを作成します。

SQlConnection con = new SqlConnection("Database connection string");
const string uName="UserName";
const string pWord="Password";
public bool getAuthenticate(string UserName,string Password)
{
    con.Open();

    SqlCommand cmd = new SqlCommand(con);
    SQlParameter[] param=new SqlParameter[]{
         new SqlParamter(uName,UserName),
         new SqlParameter(pWord,Password)
    };
    cmd.Parameters.AddRanage(param);
    SqlDataReader rd;
    rd = cmd.executeReader();

    if(rd.read())
    {
         con.Close();
         return true;
    }
    else
    {
         con.Close();
         return false;
    }
}
于 2012-08-04T06:50:51.550 に答える