protected void Button2_Click(object sender, EventArgs e) { #region LOGIN //conditions for entered data if (username_textbox.Text == "" && password_textbox.Text == "") { login_label.Visible = true; login_label.Text = "No Data entered"; } else if (username_textbox.Text == "") { login_label.Visible = true; login_label.Text = "No Username Entered"; } else if (password_textbox.Text == "") { login_label.Visible = true; login_label.Text = "No Password Entered"; } else { //start a Model Entity Object soen341dBEntities soen341dB_context = new soen341dBEntities(); //dB table constructor registration newuser = new registration(); string username = username_textbox.Text; string password = globalvariables.EncodePassword(password_textbox.Text); try { //get the retrived_user var retrieved_user = (from person in soen341dB_context.registrations where person.Password == password where person.Username == username select person).FirstOrDefault(); //check to see if a record of it exists if (retrieved_user == null) { login_label.Text = "Account Information Incorrect"; login_label.Visible = true; } else { login_label.Visible = true; login_label.Text = "Login Validated"; //encrypt url so people cannot change it to get other people's data; //Query the username to another page by using question mark variable name = Response.Redirect("LoggedIn.aspx?Username="******"Database Exception Occured :" + error.ToString(); } } #endregion }
protected void Button1_Click(object sender, EventArgs e) { #region REGISTER //check passwords match if (password_textbox1.Text != password_text2box.Text) { register_label.Visible = true; register_label.Text = "Passwords do not match"; } //check its not empty the password else if (password_text2box.Text == "" || password_textbox1.Text == "") { register_label.Visible = true; register_label.Text = "Don't leave passwords blank stupid"; } else { soen341dBEntities soen341dB_context = new soen341dBEntities(); registration newuser = new registration(); //checking if either the user or email is already registered var username_in_dB = (from a_username in soen341dB_context.registrations where a_username.Username == username_textbox.Text select a_username).FirstOrDefault(); var email_in_dB = (from an_email in soen341dB_context.registrations where an_email.email == email_textbox.Text select an_email).FirstOrDefault(); var studentid_in_dB = (from a_student_id in soen341dB_context.registrations where a_student_id.StudentId == studentid_textbox.Text select a_student_id).FirstOrDefault(); if (email_in_dB != null) { register_label.Text = "Email already registered"; register_label.Visible = true; } if (username_in_dB != null) { register_label.Text = "Username already Exists"; register_label.Visible = true; } if (studentid_in_dB != null) { register_label.Text = "Student ID Already taken"; register_label.Visible = true; } //if it doesnt retrieve records make a new record if (email_in_dB == null && username_in_dB == null) { try { newuser.Username = username_textbox.Text; newuser.Password = globalvariables.EncodePassword(password_textbox1.Text); newuser.email = email_textbox.Text; newuser.StudentId = studentid_textbox.Text; soen341dB_context.registrations.Add(newuser); soen341dB_context.SaveChanges(); } catch (Exception error) { register_label.Visible = true; register_label.Text = "Database Exception Occured: " + error.ToString(); } finally { register_label.Visible = true; register_label.Text = "Thank You for registering, You should have recieved an email from us!"; MailMessage mail = new MailMessage(); mail.To.Add(email_textbox.Text); mail.From = new MailAddress("*****@*****.**"); mail.Subject = "mYScheduler Registration Confirmation"; mail.Body = "Thank You for registering to the Concordia University mYScheduler. Your username is: " + username_textbox.Text + " Please report bugs and suggestions to [email protected]"; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "mail.atsebak.com"; smtp.Port = 587; smtp.UseDefaultCredentials = true; smtp.Credentials = new NetworkCredential("*****@*****.**", "softwareprocess"); smtp.EnableSsl = false; smtp.Send(mail); } } } #endregion }