2014-10-07 125 views
0

好吧。我對於我的生活無法弄清楚爲什麼登錄頁面代碼不起作用。也許我錯過了什麼。如果你需要完整的源代碼,我很樂意給它。我試圖讓用戶名與列表比較,找到它的密碼,然後與文本框中的密碼進行比較。那麼如果密碼匹配。重定向到帳戶頁面。網站登錄頁面無效

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; 
namespace Vanguardian_Tournaments 
{ 
    public partial class Login : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 

     protected void LoginBTN_Click(object sender, EventArgs e) 
     { 
      SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString); 
      conn.Open(); 
      string ckUser = "Select Count(*) from UserData where CFAName = '" + LoginTB.Text + "'"; 
      SqlCommand cfaComm = new SqlCommand(ckUser, conn); 
      int temp = Convert.ToInt32(cfaComm.ExecuteScalar().ToString()); 
      conn.Close(); 
      if (temp == 1) 
      { 

       conn.Open(); 
       string ckPass = "Select Password from UserData where CFAName = '" + LoginTB.Text + "'"; 
       SqlCommand PassComm = new SqlCommand(ckPass, conn); 
       string password = PassComm.ExecuteScalar().ToString().Replace(" ", ""); 
       conn.Close(); 
       if (password == LoginPassTB.Text) 
       { 
        Session["Login"] = LoginTB.Text; 
        Response.Redirect("Account.aspx"); 
       } 
       else 
       { 
        LoginLbl.Text = "CFA Name or Password is incorrect"; 
       } 
      } 
      else 
      { 
       LoginLbl.Text = "CFA Name does not exist"; 
      } 

     } 
    } 
} 
+2

你有一個SQL注入漏洞。 – SLaks 2014-10-07 02:57:11

+1

** **如何不起作用?它爆炸了嗎? – SLaks 2014-10-07 02:57:34

+0

當我以登錄表格 – 2014-10-07 03:01:11

回答

0

您是否在if語句上放置了斷點並檢查temp的值?這可能是你的代碼永遠不會進入if塊。你是否也使用asp.net提供的登錄控件?如果是的話,你不能以這種方式進行,你需要遵循以下步驟:

http://msdn.microsoft.com/en-us/library/vstudio/ms178329%28v=vs.100%29.aspx

+0

我沒有使用asp.net的任何登錄控件 – 2014-10-07 03:25:32

+0

你是否通過在那裏放置一個斷點來檢查正在爲temp轉換的值? – aditya 2014-10-07 03:27:28

+0

斷點不會停止程序。所以我假設該程序由於某種原因沒有訪問該函數。 – 2014-10-07 03:28:51