2012-08-04 7 views
0

양식 인증을 사용하고 있습니다. 여기에서는 로그인 컨트롤을 사용하고 있으며 (login.cs) 컨트롤에서 다음 메서드를 호출하여 사용자의 유효성을 검사합니다. 여기에 사용자 이름과 암호 모두에 로컬 이름을 사용하고 있으며 이제 사용자 이름과 암호를 검색 할 수 있도록 데이터베이스에 연결하려고합니다.asp.net 인증 및 승인

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; 
    } 
} 

답변

0

사용할 수 있습니다

<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

이 더 많은 도움이 필요하면 알려주세요.

-1

는 다음 시도하고 필드 이름과 암호

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; 
    } 
} 
+1

안녕하세요 SQL 주입과 SQL Server 데이터베이스를 만들! – Vedran

+0

SQL 삽입, 개체 처분 안 함, 글로벌 연결 개체 ... –