Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. //Login
  2. private void button1_Click(object sender, EventArgs e)
  3. {
  4. if (string.IsNullOrEmpty(txtUser.Text))
  5. {
  6. //Show warning
  7. }
  8. else if (string.IsNullOrEmpty(txtPass.Text))
  9. {
  10. //Show warning
  11. }
  12.  
  13. using (DataTable dt = LookupUser(txtUser.Text)) //Look into SQL data table for username and password
  14. {
  15. if (dt.Rows.Count == 0)
  16. {
  17. //Show warning
  18. }
  19. else
  20. {
  21. string dbPassword = Convert.ToString(dt.Rows[0]["pass"]);
  22. string appPassword = Encrypt(txtPass.Text);
  23. if (string.Compare(dbPassword, appPassword) == 0)
  24. {
  25. //I need to pass username value to myForm...
  26. DialogResult = DialogResult.OK;
  27. }
  28. else
  29. {
  30. //Show warning
  31. }
  32. }
  33. }
  34.  
  35. //Program.cs
  36. static void Main()
  37. {
  38. Application.EnableVisualStyles();
  39. Application.SetCompatibleTextRenderingDefault(false);
  40. DialogResult result;
  41. using (var loginForm = new Login())
  42. result = loginForm.ShowDialog();
  43. if (result == DialogResult.OK)
  44. {
  45. Application.Run(new myForm());
  46. }
  47. }
  48.  
  49. public string UserName {get; private set;}
  50.  
  51. if (string.Compare(dbPassword, appPassword) == 0)
  52. {
  53. UserName = txtUser.Text;
  54. //I need to pass username value to myForm...
  55. DialogResult = DialogResult.OK;
  56. }
  57. else
  58. {
  59. //Show warning
  60. }
  61.  
  62. DialogResult result;
  63. using (var loginForm = new Login())
  64. result = loginForm.ShowDialog();
  65. if (result == DialogResult.OK)
  66. {
  67. var username = loginForm.UserName;
  68. Application.Run(new myForm(username));
  69. }
  70.  
  71. }
  72. Siman_dbEntities db = new Siman_dbEntities();
  73. public string UserNameLogedIn;
  74. private void btnLogin_Click(object sender, EventArgs e)
  75. {
  76. var login = from b in db.Tbl_Users.Where(b => b.Username == txtUsername.Text && b.Password == txt_Password.Text)
  77. select b;
  78. if (login.Count()==1)
  79. {
  80. this.Hide();
  81. main frmmain = new main();
  82. frmmain.Show();
  83. }
  84. var query = db.Tbl_Users.Where(c => c.Username == txtUsername.Text).Single();
  85. UserNameLogedIn = query.Name.ToString();
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement