protected void btnVerifyEmail_Click(object sender, EventArgs e) { string email = txtVerifyEmail.Text; if (email == "") { smlVerifyEmailHelp.InnerText = "Please enter your email address"; return; } else { smlVerifyEmailHelp.InnerText = ""; } UserService.UserService proxy = new UserService.UserService(); bool verifyEmail = proxy.ValidateEmail(email); if (verifyEmail) { smlVerifyEmailHelp.InnerText = "Email does not belong to a profile, try again"; return; } else { smlVerifyEmailHelp.InnerText = ""; } UserService.User serviceUser = proxy.GetUserByEmail(email); User recoverUser = new User(serviceUser.Username, serviceUser.FirstName, serviceUser.LastName, serviceUser.Password, serviceUser.ProfileImage, serviceUser.HomeAddress, serviceUser.BillingAddress, serviceUser.EmailAddress, serviceUser.Phone, serviceUser.SecretQuestions, serviceUser.SecretAnswers, serviceUser.Verified); int arrayIndex; int secretQuestion = recoverUser.GetRandomQuestion(out arrayIndex); lblUsernameSecretQuestion.InnerText = securityQuestions[secretQuestion]; Session["UsernameRetrieve"] = recoverUser.Username; Session["SecretAnswer"] = recoverUser.GetSecretAnswer(arrayIndex); divUsernameSecretQuestion.Visible = true; }
protected void btnSubmitRegister_Click(object sender, EventArgs e) { string username = txtRegUsername.Text; string password = txtRegPassword.Text; string firstName = txtRegFirstName.Text; string lastName = txtRegLastName.Text; string emailAddress = txtRegEmail.Text; string homeAddress = txtRegHomeAddress.Text; string billingAddress = txtRegBillingAddress.Text; long phoneNumber; string profileImage = txtRegImage.Text; string securityQuestion1 = txtRegSecurity1.Text; string securityQuestion2 = txtRegSecurity2.Text; string securityQuestion3 = txtRegSecurity3.Text; string secretAnswers = securityQuestion1 + "," + securityQuestion2 + "," + securityQuestion3; string secretQuestions = ddlSecurity1.SelectedValue + "," + ddlSecurity2.SelectedValue + "," + ddlSecurity3.SelectedValue; bool good = true; MD5CryptoServiceProvider hasher = new MD5CryptoServiceProvider(); string addSalt = string.Concat("ummm salty ", password); byte[] hash = hasher.ComputeHash(Encoding.Unicode.GetBytes(addSalt)); if (username == "") { smlRegUsernameHelp.InnerText = "Please enter a username"; good = false; } else { smlRegUsernameHelp.InnerText = ""; } if (password == "") { smlRegPasswordHelp.InnerText = "Please enter a password"; good = false; } else { smlRegPasswordHelp.InnerText = ""; } if (firstName == "") { smlRegFirstNameHelp.InnerText = "Please enter a first name"; good = false; } else { smlRegFirstNameHelp.InnerText = ""; } if (lastName == "") { smlRegLastNameHelp.InnerText = "Please enter a last name"; good = false; } else { smlRegLastNameHelp.InnerText = ""; } if (emailAddress == "") { smlRegEmailHelp.InnerText = "Please enter an email address"; good = false; } else { smlRegEmailHelp.InnerText = ""; } if (homeAddress == "") { smlRegHomeAddressHelp.InnerText = "Please enter a home address"; good = false; } else { smlRegHomeAddressHelp.InnerText = ""; } if (billingAddress == "") { smlRegBillingAddressHelp.InnerText = "Please enter a billing address"; good = false; } else { smlRegBillingAddressHelp.InnerText = ""; } if (!Int64.TryParse(txtRegPhone.Text, out phoneNumber)) { smlRegPhoneHelp.InnerText = "Please enter a valid phone number"; good = false; } else { smlRegPhoneHelp.InnerText = ""; } if (profileImage == "") { smlRegImageHelp.InnerText = "Please enter a valid image URL"; good = false; } else { smlRegImageHelp.InnerText = ""; } if (securityQuestion1 == "") { smlRegQuestion1Help.InnerText = "Please enter a question response"; good = false; } else { smlRegQuestion1Help.InnerText = ""; } if (securityQuestion2 == "") { smlRegQuestion2Help.InnerText = "Please enter a question response"; good = false; } else { smlRegQuestion2Help.InnerText = ""; } if (securityQuestion3 == "") { smlRegQuestion3Help.InnerText = "Please enter a question response"; good = false; } else { smlRegQuestion3Help.InnerText = ""; } if (!good) { return; } UserService.UserService proxy = new UserService.UserService(); bool validateUsername = proxy.ValidateUsername(username); if (!validateUsername) { smlRegUsernameHelp.InnerText = "Username already taken, pick a new one"; return; } else { smlRegUsernameHelp.InnerText = ""; } bool validateEmail = proxy.ValidateEmail(emailAddress); if (!validateEmail) { smlRegEmailHelp.InnerText = "Email is taken, please try again with a new one"; return; } else { smlRegEmailHelp.InnerText = ""; } try { MailAddress fromAddress = new MailAddress("*****@*****.**", "Not Twitter"); MailAddress toAddress = new MailAddress(emailAddress, "New User"); MailMessage verificationMail = new MailMessage(fromAddress.Address, toAddress.Address); verificationMail.Subject = "Not Twitter: New Account Verification"; verificationMail.Body = "Click this link to verify your new account. http://localhost:62631/Verification.aspx?uname=" + username + "&mail=true"; SmtpClient client = new SmtpClient(); client.Host = "smtp.gmail.com"; client.Port = 587; client.EnableSsl = true; client.UseDefaultCredentials = false; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Credentials = new NetworkCredential(fromAddress.Address, "ajcqwouuvihbodbc"); client.Send(verificationMail); } catch { smlRegEmailHelp.InnerText = "Invalid email address, try again"; return; } smlRegEmailHelp.InnerText = ""; UserService.User user1 = new UserService.User(); user1.Username = username; user1.FirstName = firstName; user1.LastName = lastName; user1.Password = TwitterClassLibrary.Encryption.PasswordEncryption.EncryptPassword(password); user1.EmailAddress = emailAddress; user1.HomeAddress = homeAddress; user1.BillingAddress = billingAddress; user1.Phone = phoneNumber.ToString(); user1.ProfileImage = profileImage; user1.SecretQuestions = secretQuestions; user1.SecretAnswers = secretAnswers; user1.Verified = "false"; bool addUser = proxy.AddUser(user1); if (!addUser) { smlRegUsernameHelp.InnerText = "User registration failed, try again later"; return; } else { smlRegUsernameHelp.InnerText = ""; } Session["Username"] = txtRegUsername.Text; if (chkRegCookie.Checked) { Response.Cookies["Username"].Value = txtRegUsername.Text; } Response.Redirect("Verification.aspx?mail=false"); }