Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. /// <summary>
  2. /// Checks the password for the given user name
  3. /// </summary>
  4. /// <param name="uName">The username which we we want password of</param>
  5. /// <returns>The password of the given user name</returns>
  6. public string GetPassword(string uName)
  7. {
  8. OleDbCommand cmd = new OleDbCommand("GetPassword", _connection);
  9. cmd.CommandType = CommandType.StoredProcedure;
  10. OleDbParameter param;
  11. param = cmd.Parameters.Add("input", OleDbType.BSTR);
  12. param.Direction = ParameterDirection.Input;
  13. param.Value = uName;
  14. try
  15. {
  16. _connection.Open();
  17. return cmd.ExecuteScalar().ToString();
  18. }
  19. catch(Exception ex)
  20. {
  21. throw ex;
  22. }
  23. finally
  24. {
  25. _connection.Close();
  26. }
  27. }
  28.  
  29. /// <summary>
  30. /// The function adds new user to the user's table in the database
  31. /// </summary>
  32. /// <param name="uName">The new user's name</param>
  33. /// <param name="uPass">The new user's password</param>
  34. /// <param name="uMail">The new user's email</param>
  35. public void AddUser(string uName, string uPass, string uMail)
  36. {
  37. OleDbCommand cmd = new OleDbCommand("AddUser", _connection);
  38. cmd.CommandType = CommandType.StoredProcedure;
  39. OleDbParameter param;
  40. param = cmd.Parameters.Add("userName", OleDbType.BSTR);
  41. param.Direction = ParameterDirection.Input;
  42. param.Value = uName;
  43.  
  44. param = cmd.Parameters.Add("userPass", OleDbType.BSTR);
  45. param.Direction = ParameterDirection.Input;
  46. param.Value = uPass;
  47.  
  48. param = cmd.Parameters.Add("userMail", OleDbType.BSTR);
  49. param.Direction = ParameterDirection.Input;
  50. param.Value = uMail;
  51. try
  52. {
  53. _connection.Open();
  54. if (cmd.ExecuteNonQuery() == 0)
  55. throw new Exception("User was not added to the database");
  56. }
  57. catch (Exception ex)
  58. {
  59. throw ex;
  60. }
  61. finally
  62. {
  63. _connection.Close();
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement