Saturday, November 27, 2021

Creating Login logic for asp.net C# and Stored procedure for finding Login and password

 

  1. Create procedure [dbo].[spLogin]  
  2. (  
  3. @Email nvarchar(50),  
  4. @Password nvarchar(50)  
  5. )  
  6. as  
  7. begin  
  8. Select COUNT(*) from UserRegistration where Email=@Email and Password=@Password   
  9. end  
  10. ---------------------------------
  11. Clicking on Login button

  12. protected void btnLogin_Click(object sender, EventArgs e)  
  13.         {  
  14.               
  15.             string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;  
  16.             using (SqlConnection con=new SqlConnection(CS))  
  17.             {  
  18.                 SqlCommand cmd = new SqlCommand("spLogin", con);  
  19.                 cmd.CommandType = CommandType.StoredProcedure;  
  20.                 con.Open();  
  21.                 cmd.Parameters.AddWithValue("@Email",txtEmail.Text.Trim());  
  22.                 cmd.Parameters.AddWithValue("@Password", Decrypt(txtPassword.Text.Trim()));  
  23.                 int Username = (Int32)cmd.ExecuteScalar();  
  24.                 if (Username == 1)  
  25.                 {  
  26.                     Session["Username"] = txtEmail.Text;  
  27.                     Response.Redirect("Welcome.aspx");  
  28.                     Session.RemoveAll();  
  29.                       
  30.                 }  
  31.                 else  
  32.                 {  
  33.                     lblMessage.ForeColor = System.Drawing.Color.Red;  
  34.                     lblMessage.Text = "Invalid username and password";  
  35.                 }  
  36.             }  
  37.         } 
  38. reference:- https://www.c-sharpcorner.com/blogs/how-to-login-with-encrypted-password-in-asp-net
  39. https://www.c-sharpcorner.com/blogs/how-to-create-user-registration-form-with-encrypted-password-using-asp-net#ReadAndPostComment

No comments:

Post a Comment