PageRenderTime 60ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/BaliEnterpriseSystems/BaliEnterpriseSystems/ForgotPassword.aspx.cs

https://github.com/sirivedula/BEST
C# | 90 lines | 83 code | 7 blank | 0 comment | 6 complexity | c89a2ff4924ff27af8371435371e01ef MD5 | raw file
  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 BaliEnterpriseSystems.BestObjects;
  8. namespace BaliEnterpriseSystems
  9. {
  10. public partial class ForgotPassword : System.Web.UI.Page
  11. {
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. }
  15. protected void Page_LoadComplete(object sender, EventArgs e)
  16. {
  17. if (IsPostBack)
  18. {
  19. if (emailid.Value.Length == 0)
  20. {
  21. ltrMsg.Text = "EMail address can not be blank.";
  22. }
  23. else
  24. {
  25. BestUser bsUser = new BestUser();
  26. bsUser.LoadRows("emailid=?", "emailid", emailid.Value, "username");
  27. bsUser.currentRowId = 0;
  28. try
  29. {
  30. if (!bsUser.CurrentRow.IsNew)
  31. {
  32. bsUser.overrideEdit = true;
  33. string randPwd = RandomString(8);
  34. bsUser.password = Utils.GetMD5Hash(randPwd);
  35. bsUser.passwordExpiration = DateTime.Today.AddDays(7);
  36. CurrentUser CUser = new CurrentUser(bsUser.userName);
  37. if (bsUser.CurrentRow.Save())
  38. {
  39. ltrMsg.Text = "Password Reset done and an email sent to you. <a href=\"Login.aspx\">Please Login</a>" ;
  40. CUser.emailUtil.Send(bsUser.emailId, "BLC Login Information", @"<h2>Password Reset</h2><br><h3>Your login information is enclosed.</h3>
  41. <b>Accessing Your Account</b><br>
  42. Step 1:<br>
  43. Click the link below or enter the URL below into your web browser<br>
  44. Address: <a href=""http://best.vasbal.com"">Bali Learning Center Login</a><br><br>
  45. Step 2:<br>
  46. Enter the following user name and temporary password.<br>
  47. User Name: <b>" + bsUser.userName + @"</b><br>
  48. Password: <b>" + randPwd + @"</b><br><br>
  49. <h3>This temporary password expires in 24 hours.</h3><br><br>
  50. You will be prompted to change your user name and password during your initial log in as well as answer a few security related questions. <br>
  51. <br>
  52. <br>
  53. <br>
  54. Thank you,<br>
  55. Bali Learning Center", bsUser.firstName + " " + bsUser.lastName);
  56. }
  57. }
  58. }
  59. catch (Exception ex)
  60. {
  61. ltrMsg.Text = ex.Message;
  62. }
  63. }
  64. }
  65. }
  66. private readonly Random _rng = new Random();
  67. private const string _chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()~-_+={[}}|;:<.>,/?";
  68. private string RandomString(int size)
  69. {
  70. char[] buffer = new char[size];
  71. for (int i = 0; i < size; i++)
  72. {
  73. buffer[i] = _chars[_rng.Next(_chars.Length)];
  74. }
  75. return new string(buffer);
  76. }
  77. }
  78. }