Subin Thomas

Subin Thomas

  • NA
  • 4.9k
  • 117.6k

login code not working

Feb 13 2019 11:10 PM
i have a login table which contains userid username password lastvisited and so on i wrote a code for login but its not working below is the code
 
and also the password is not visible in the database its encrypted
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Data;  
  8. using System.Data.SqlClient;  
  9. using System.Configuration;  
  10. using System.IO;  
  11. using System.Security.Cryptography;  
  12.   
  13. namespace Vas  
  14. {  
  15.     public partial class CostMonitoring : System.Web.UI.Page  
  16.     {  
  17.         public static string con_Vas = ConfigurationManager.ConnectionStrings["vas_con"].ConnectionString;  
  18.         SqlConnection condiv = new SqlConnection(con_Vas);  
  19.   
  20.         protected void Page_Load(object sender, EventArgs e)  
  21.         {  
  22.   
  23.         }  
  24.   
  25.   
  26.   
  27.         protected void btnLogin_Click(object sender, EventArgs e)  
  28.         {  
  29.   
  30.                 
  31.            
  32.   
  33.   
  34.   
  35.             string strSelect = "SELECT COUNT(*) FROM  VAS_Login WHERE UserID = @Username AND Password = @Password";  
  36.   
  37.             SqlConnection con = new SqlConnection(con_Vas);  
  38.             SqlCommand cmd = new SqlCommand("Vas_adminvas_login", con);  
  39.             cmd.CommandType = CommandType.StoredProcedure;  
  40.             //SqlCommand cmd = new SqlCommand();  
  41.             cmd.Connection = con;  
  42.             cmd.CommandType = CommandType.Text;  
  43.             cmd.CommandText = strSelect;  
  44.   
  45.             SqlParameter username = new SqlParameter("@Username", SqlDbType.NVarChar, 50);  
  46.             username.Value = txtusername.Text.Trim().ToString();  
  47.             cmd.Parameters.Add(username);  
  48.   
  49.             SqlParameter password = new SqlParameter("@Password", SqlDbType.NVarChar, 100);  
  50.             password.Value =(txtpass.Text.Trim());  
  51.             cmd.Parameters.Add(password);  
  52.             // cmd.CommandTimeout = 1000;  
  53.   
  54.             con.Open();  
  55.             int result = (Int32)cmd.ExecuteScalar();  
  56.             con.Close();  
  57.   
  58.             if (result >= 1)  
  59.             {  
  60.   
  61.                 Response.Redirect("www.google.com");  
  62.             }  
  63.             else  
  64.             {  
  65.                 Label1.Text = "incorrect password or username";  
  66.             }  
  67.   
  68.   
  69.   
  70.         }  
  71.     }  


Answers (7)