Guest User

Untitled

a guest
Sep 1st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. Custom Login ASP.NET C#
  2. using System;
  3. using System.Data;
  4. using System.Configuration;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12.  
  13.  
  14. public partial class Login : System.Web.UI.Page
  15. {
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18.  
  19. }
  20.  
  21. // Custom login control
  22. protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
  23. {
  24. try
  25. {
  26. string uname = Login1.UserName.Trim();
  27. string password = Login1.Password.Trim();
  28.  
  29. bool flag = AuthenticateUser(uname, password);
  30. if (flag == true)
  31. {
  32. e.Authenticated = true;
  33. Login1.DestinationPageUrl = "Default.aspx";
  34. }
  35. else
  36. e.Authenticated = false;
  37. }
  38. catch (Exception)
  39. {
  40. e.Authenticated = false;
  41. }
  42. }
  43.  
  44. private bool AuthenticateUser(string uname, string password)
  45. {
  46. bool bflag = false;
  47. string connString = "Server=DEVSERVER;User ID=sa;Password=whatpassword;Database=CommonUser";
  48. string connstring2 = "Server=DEVSERVER;User ID=sa;Password=whatpassword;Database=Admins";
  49. string strSQL = "Select * from dbo.Users where Username ='" + uname + "' and Password ='" + password + "'";
  50. DataSet userDS = new DataSet();
  51. SqlConnection m_conn;
  52. SqlDataAdapter m_dataAdapter;
  53. SqlCommand m_Command;
  54. try
  55. {
  56. m_conn = new SqlConnection(connString);
  57. m_conn.Open();
  58. m_dataAdapter = new SqlDataAdapter(strSQL, m_conn);
  59. m_dataAdapter.Fill(userDS);
  60. m_conn.Close();
  61. }
  62. catch (Exception)
  63. {
  64. userDS = null;
  65. }
  66.  
  67. if (userDS != null)
  68. {
  69. if (userDS.Tables[0].Rows.Count > 0)
  70. bflag = true;
  71. }
  72. return bflag;
  73.  
  74. }
  75. }
Add Comment
Please, Sign In to add comment