2016-05-30 3 views
0

私はASP.NETでLogin-pageをやっています.3回失敗した後にユーザーをブロックし、10分後にブロックを解除したいと思います。私はログインコントロールを使用しなかったので、メンバーシッププロバイダを使用することはできませんので、タイムアウトを使用することを考えました。以下のコードを修正してユーザーをブロックおよびブロック解除するにはどうすればよいですか?ASP.NETアプリケーションでタイムアウトを使用するには?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data.SqlClient; 
using System.Configuration; 
using System.Data; 
using Replicon.Cryptography.SCrypt; 

namespace WebApplication1 
{ 
    public partial class SignIn : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 

     public class LoginAttempt { public DateTime AttemptTime {get;set;} } 
     protected void Button1_Click(object sender, EventArgs e) 
     { 
      String CS = ConfigurationManager.ConnectionStrings["MyDatabaseConnectionString1"].ConnectionString; 
      using (SqlConnection con = new SqlConnection(CS)) 
      { 

       SqlCommand cmd = new SqlCommand("select * from Users where [email protected]", con); 
       cmd.Parameters.Add("@Username", Username.Text); 
       con.Open(); 
       SqlDataAdapter sda = new SqlDataAdapter(cmd); 
       DataTable dt = new DataTable(); 
       sda.Fill(dt); 
       if (dt.Rows.Count != 0) 
       { 
        foreach (DataRow row in dt.Rows) 
        { 
         if (Replicon.Cryptography.SCrypt.SCrypt.Verify(Password.Text, (string)row["Password"])) 
         { 
          Session["USERNAME "] = Username.Text; 
          Response.Redirect("~/UserHome.aspx"); 
          return; 
         } 

         { lblError.Text = "Invalid Username or Password !"; } 
        } 
       } 


      } 
     } 


    } 
} 

答えて

0

あなたがエラーに直面した場合、あなたは私が何を変更する必要があり、

if(Session["DateTime"]==null) 
{ 
String CS = ConfigurationManager.ConnectionStrings["MyDatabaseConnectionString1"].ConnectionString; 
      using (SqlConnection con = new SqlConnection(CS)) 
      { 

       SqlCommand cmd = new SqlCommand("select * from Users where [email protected]", con); 
       cmd.Parameters.Add("@Username", Username.Text); 
       con.Open(); 
       SqlDataAdapter sda = new SqlDataAdapter(cmd); 
       DataTable dt = new DataTable(); 
       sda.Fill(dt); 





       if (dt.Rows.Count != 0) 
       { 
        foreach (DataRow row in dt.Rows) 
        { 
         if (Replicon.Cryptography.SCrypt.SCrypt.Verify(Password.Text, (string)row["Password"])) 
         { 
          Session["USERNAME "] = Username.Text; 
          Response.Redirect("~/UserHome.aspx"); 
          return; 
         } 

         { lblError.Text = "Invalid Username or Password !"; } 
        } 
       } 
else 
{ 
if(Convert.ToInt32(Session["errorlogin"])>3) 
{ 
    Session["DateTime"]=DateTime.Now; 
} 
Session["errorlogin"]=Convert.ToInt32(Session["errorlogin"])+1; 


} 
} 
} 
+0

そして、Global.asaxの中でグローバルasaxでセッション値を初期する必要があるセッション を使用することができますか?セッション開始時に –

+0

開始セッション["DateTime"]とセッション["errorlogin"] –

+0

どのような値で初期化しますか? –

関連する問題