PageRenderTime 60ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Kronos/Kronos/Default.aspx.cs

https://github.com/lle/soen341kronos
C# | 92 lines | 68 code | 16 blank | 8 comment | 14 complexity | 39493727b7cf5d114eeebaf2458ed206 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 System.Data.SqlClient;
  8. using System.Data;
  9. using System.Data.Linq;
  10. using System.Configuration;
  11. using Kronos.CLASSES;
  12. namespace Kronos
  13. {
  14. public partial class Default : System.Web.UI.Page
  15. {
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. #region ON_START
  19. //Don't show text on the main page
  20. login_label.Visible = false;
  21. #endregion
  22. }
  23. protected void Button2_Click(object sender, EventArgs e)
  24. {
  25. #region LOGIN
  26. //conditions for entered data
  27. if (username_textbox.Text == "" && password_textbox.Text == "")
  28. {
  29. login_label.Visible = true;
  30. login_label.Text = "No Data entered";
  31. }
  32. else if (username_textbox.Text == "") { login_label.Visible = true; login_label.Text = "No Username Entered"; }
  33. else if (password_textbox.Text == "") { login_label.Visible = true; login_label.Text = "No Password Entered"; }
  34. else
  35. {
  36. //start a Model Entity Object
  37. soen341dBEntities soen341dB_context = new soen341dBEntities();
  38. //dB table constructor
  39. registration newuser = new registration();
  40. string username = username_textbox.Text;
  41. string password = globalvariables.EncodePassword(password_textbox.Text);
  42. try
  43. {
  44. //get the retrived_user
  45. var retrieved_user = (from person in soen341dB_context.registrations
  46. where person.Password == password
  47. where person.Username == username
  48. select person).FirstOrDefault();
  49. //check to see if a record of it exists
  50. if (retrieved_user == null) { login_label.Text = "Account Information Incorrect"; login_label.Visible = true; }
  51. else
  52. {
  53. login_label.Visible = true;
  54. login_label.Text = "Login Validated";
  55. //encrypt url so people cannot change it to get other people's data;
  56. //Query the username to another page by using question mark variable name =
  57. Response.Redirect("LoggedIn.aspx?Username=" + Encoder_BASE64(username));
  58. }
  59. }
  60. catch (Exception error)
  61. {
  62. login_label.Visible=true;
  63. login_label.Text = "Database Exception Occured :" + error.ToString();
  64. }
  65. }
  66. #endregion
  67. }
  68. #region Encode64
  69. public static string Encoder_BASE64(string toEncode)
  70. {
  71. byte[] toEncodeAsBytes = System.Text.Encoding.Unicode.GetBytes(toEncode);
  72. return System.Convert.ToBase64String(toEncodeAsBytes);
  73. }
  74. #endregion
  75. }
  76. }