public void ValidatePassword_myparol() { bool password = PasswordClass.ValidatePassword("myparol", "1306b1dbf201d74b03a144ab22e6d203"); bool expected = true; Assert.AreEqual(expected, password); }
} //UpdateEmployee #endregion /// <summary> /// Заполняет объект типа Employee информацией из формы. /// </summary> /// <param name="employee">Сотрудник, который будет заполнен инф-цией из формы.</param> private Employee GetEmployeeFromForm() { string photoPath = null; //Проверяем наличие фото. if (photoPictureBox.Image != null) { if (photoPictureBox.Tag != null) //если false значит фото уже есть в нужной папке и мы просто записываем относительный путь иначе сначала копируем файл. { string destFilePath = photoPictureBox.Tag as string; System.IO.File.Copy(photoOpenFileDialog.FileName, destFilePath); } photoPath = employeePhotoFolder + toolTip.GetToolTip(photoPictureBox); }//else Employee employee = new Employee ( employeeId: 0, photo: photoPath, lastName: lastNameTextBox.Text.Trim(), firstName: firstNameTextBox.Text.Trim(), middleName: (!String.IsNullOrWhiteSpace(middleNameTextBox.Text)) ? middleNameTextBox.Text.Trim() : null, birthDate: birthDateTimePicker.Value, hireDate: hireDateTimePicker.Value, dismissalDate: null, note: (!String.IsNullOrWhiteSpace(descrRichTextBox.Text)) ? descrRichTextBox.Text.Trim() : null, passportNum: (!String.IsNullOrWhiteSpace(passportNumTextBox.Text)) ? passportNumTextBox.Text.Trim() : null, title: (!String.IsNullOrWhiteSpace(titleTextBox.Text)) ? titleTextBox.Text.Trim() : null, accessLayer: accessLayerComboBox.SelectedItem as string, contactInfo: GetContactInfo(), login: loginTextBox.Text.Trim(), password: PasswordClass.GetHashString(passwordTextBox.Text.Trim()) //получаем хэш введенного пароля. ); return(employee); }//GetEmployeeFromForm
public void ValidatePassword_1() { bool password = PasswordClass.ValidatePassword("1", "06d49632c9dc9bcb62aeaef99612ba6b"); bool expected = true; Assert.AreEqual(expected, password); }
public void GetHashString_1() { string password = PasswordClass.GetHashString("1"); string expected = "06d49632c9dc9bcb62aeaef99612ba6b"; Assert.AreEqual(expected, password); }
public void GetHashString_myparol() { string password = PasswordClass.GetHashString("myparol"); string expected = "1306b1dbf201d74b03a144ab22e6d203"; Assert.AreEqual(expected, password); }
protected void btnregister_Click(object sender, EventArgs e) { string hashpassword = PasswordClass.Hashpassword(txtpswd.Text); SqlConnection con = new SqlConnection("Data Source=WIN-T5M51LAKF72\\MSSQLSERVER2; Initial Catalog=BookStore; Integrated Security=true;"); SqlCommand cmd = new SqlCommand("uspcustinsert", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@cname", txtcname.Text); cmd.Parameters.AddWithValue("@username", Textuname.Text); cmd.Parameters.AddWithValue("@email", txtemail.Text); cmd.Parameters.AddWithValue("@phone", txtphn.Text); cmd.Parameters.AddWithValue("@gender", ddlgender.SelectedItem.Text); cmd.Parameters.AddWithValue("@dateofbirth", Convert.ToDateTime(txtdob.Text)); cmd.Parameters.AddWithValue("@pasword", hashpassword); if (con.State == ConnectionState.Closed) { con.Open(); } int res = cmd.ExecuteNonQuery(); if (res > 0) { Response.Redirect("CustomerLogin.aspx"); } }
private string result() { string res; if (digitCheckBox.Checked) { if (lowCheckBox.Checked) { if (upCheckBox.Checked) { res = PasswordClass.pinCodeWithDigitsLetters((int)lengthUpDown.Value, (int)digit1UpDown.Value, (int)digit2UpDown.Value, lComboBox1.Text[0], lComboBox2.Text[0], uComboBox1.Text[0], uComboBox2.Text[0]); } else { res = PasswordClass.pinCodeWithDigitsLowerCaseLetters((int)lengthUpDown.Value, (int)digit1UpDown.Value, (int)digit2UpDown.Value, lComboBox1.Text[0], lComboBox2.Text[0] ); } } else if (upCheckBox.Checked) { res = PasswordClass.pinCodeWithDigitsUpperCaseLetters((int)lengthUpDown.Value, (int)digit1UpDown.Value, (int)digit2UpDown.Value, uComboBox1.Text[0], uComboBox2.Text[0] ); } else { res = PasswordClass.pinCodeWithDigits((int)lengthUpDown.Value, (int)digit1UpDown.Value, (int)digit2UpDown.Value ); } } else if (lowCheckBox.Checked) { if (upCheckBox.Checked) { res = PasswordClass.pinCodeWithDifferentCaseLetters((int)lengthUpDown.Value, lComboBox1.Text[0], lComboBox2.Text[0], uComboBox1.Text[0], uComboBox2.Text[0] ); } else { res = PasswordClass.pinCodeWithLowerCaseLetters((int)lengthUpDown.Value, lComboBox1.Text[0], lComboBox2.Text[0] ); } } else { res = PasswordClass.pinCodeWithUpperCaseLetters((int)lengthUpDown.Value, uComboBox1.Text[0], uComboBox2.Text[0] ); } return(res); }
protected void btn_login_Click(object sender, EventArgs e) { String hashpassword = PasswordClass.Hashpassword(txtpswd.Text); SqlConnection con = new SqlConnection("Data Source=WIN-T5M51LAKF72\\MSSQLSERVER2; Initial Catalog=BookStore; Integrated Security=true;"); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("select * from customer where username=@username and password=@pasword", con); cmd.Parameters.AddWithValue("@username", txtuname.Text); cmd.Parameters.AddWithValue("@pasword", hashpassword); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); if (chkremember.Checked) { HttpCookie cookie = new HttpCookie("userinfo"); cookie["username"] = txtuname.Text; cookie["password"] = hashpassword; cookie.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(cookie); } else { HttpCookie cookie = new HttpCookie("userinfo"); if (cookie != null) { cookie.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(cookie); } } if (dt.Rows.Count > 0) { Session["username"] = txtuname.Text; Session["password"] = hashpassword; Session["Logstatus"] = true; Response.Redirect("customerview.aspx"); } else { Response.Write("Invalid Credentials"); } }
} //CancelButton_MouseClick private void okButton_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { //Проверяем введенные данные. string inputPasswordHash = PasswordClass.GetHashString(passwordTextBox.Text.Trim()); try { var employees = PartsDAL.FindEmployees().Where(empl => empl.Login == loginTextBox.Text.Trim()); Employee employee = employees.Where(empl => empl.Password == inputPasswordHash).First(); Form1.CurEmployee = employee; _isCorrectClose = true; this.Close(); }//try catch { toolTip.Show("Введены неверные данные.", this, okButton.Location, 3000); } //var employeesList = PartsDAL.FindAllEmployees().Where(empl => empl.GetFullName() == fullNameTextBox.Text.Trim() && empl.Password == inputPasswordHash).First(); } //if }
protected void sendCode_Click(object sender, EventArgs e) { string Email = txtemail.Text; PasswordClass recovery = new PasswordClass(); recovery.getUser(Email); string Fname = recovery.Fname; if (recovery.Fname == null) { txtemail.Text = ""; lblmsg.Text = "Enter a Valid Email"; } else { string Code; Code = Guid.NewGuid().ToString(); PasswordClass password = new PasswordClass(); password.UploadCode(Email, Code); try { using (MailMessage mm = new MailMessage("*****@*****.**", Email)) { mm.Subject = "Password Recovery"; mm.Body = @"<a href=http://localhost:34227/UserControl/Template/User/ResetPassword.aspx?Email=" + Email + "&Code=" + Code + ">Click here to change your password</a>"; mm.IsBodyHtml = false; SmtpClient smtp = new SmtpClient("smtp-relay.sendinblue.com"); smtp.Host = "smtp-relay.sendinblue.com"; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential("*****@*****.**", "rbjUEh8YVNZC0vfI"); smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); } /* MailMessage Msg = new MailMessage(); * MailAddress mailAddress = new MailAddress("*****@*****.**", "Annex Team"); * Msg.From=(mailAddress); * MailAddress recieveraddress = new MailAddress(Email,Fname); * Msg.To.Add(recieveraddress); * Msg.Subject ="Password Recovery"; * Msg.Body = "<a href=http://localhost:34227/UserControl/Template/User/ResetPassword.aspx?Email="+Email+"&Code="+Code+ ">Click here to change your password</a>"; * Msg.IsBodyHtml = false; * SmtpClient smtp = new SmtpClient("smtp-relay.sendinblue.com", 587); * //smtp.Host = ; * smtp.Host = "smtp-relay.sendinblue.com"; * smtp.Port = 587; * smtp.EnableSsl = true; * smtp.DeliveryMethod = SmtpDeliveryMethod.Network; * smtp.UseDefaultCredentials = false; * smtp.Credentials = new System.Net.NetworkCredential(Msg.From.Address, "rbjUEh8YVNZC0vfI"); * smtp.Send(Msg);*/ //Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...');if(alert){ window.location='~/UserControl/Template/User/RecoverPassword.aspx';}</script>"); ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true); } catch (Exception ex) { Console.WriteLine("{0} Exception caught.", ex); } } }
/// <summary>保存会员信息</summary> private void btnSave_Click(object sender, EventArgs e) { if (this.txtCard.Text.Trim() == "") { MessageBox.Show("【会员卡号】不能为空,请输入!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.txtCard.Focus(); return; } Member objMember = new Member(); objMember.ID = this.txtCard.Text; objMember.Name = this.txtName.Text.Trim(); if (objMember.Name == "") { objMember.Name = "散客会员"; } objMember.Status = this.cboStatus.SelectedIndex; objMember.CardID = int.Parse(this.cboLevel.SelectedValue.ToString()); objMember.Password = PasswordClass.EncryptMD5(this.txtPassword.Text.Trim()); objMember.Remark = this.txtRemark.Text.Trim(); objMember.Sex = this.cboSex.SelectedIndex; if (this.cboMonth.Text == "") { objMember.Month = 0; } else { objMember.Month = int.Parse(this.cboMonth.Text); } if (this.cboDay.Text == "") { objMember.Day = 0; } else { objMember.Day = int.Parse(this.cboDay.Text); } objMember.Phone = this.txtPhone.Text; objMember.Address = this.txtAddress.Text.Trim(); objMember.Other = this.txtOther.Text.Trim(); objMember.JoinDate = this.dtpJoin.Value; objMember.IDCard = this.txtIDCard.Text.Trim(); string strTempId = objMember.ExistsMemberCard(objMember.ID); if (this.m_strMemberId != "") { objMember.ID = this.m_strMemberId; if (strTempId != "" && strTempId != this.m_strMemberId) { MessageBox.Show("已经存在相同会员卡号,请输重新输入!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.txtCard.Focus(); return; } objMember.UpdateMember(); } else { if (strTempId != "") { MessageBox.Show("已经存在相同会员卡号,请输重新输入!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.txtCard.Focus(); return; } objMember.InsertMember(); } DialogResult = DialogResult.OK; this.Close(); }