using System; using System.Windows.Forms; using Tanshu.Accounts.Repository; using Tanshu.Accounts.Contracts; using Tanshu.Accounts.Helpers; using Tanshu.Accounts.Entities.Auth; namespace Tanshu.Accounts.PointOfSale { public partial class ChangePassword : Form { public ChangePassword() { InitializeComponent(); } private void ChangePassword_Load(object sender, EventArgs e) { txtUsername.Text = Session.User.Name; } private void button2_Click(object sender, EventArgs e) { this.Close(); } private void btnCreateUSer_Click(object sender, EventArgs e) { if (txtPassword.Text.Trim() == "") MessageBox.Show("Old password can not be blank", "Blank not allowed"); else { if (txtnewPassword.Text.Trim() == "") MessageBox.Show("New password can not be blank", "Blank not allowed"); else { if (txtnewPassword.Text.Trim() != txtConfirmPassword.Text.Trim()) MessageBox.Show("New password not matched to confirm password", "Password not matched"); else { if (ChangeUserPassword()) { MessageBox.Show("Password changed", "Confirm"); this.Close(); } else MessageBox.Show("old Password not matched for user", "Wrong Password"); } } } } private bool ChangeUserPassword() { User userEntity = new User(); userEntity.Name = txtUsername.Text.Trim(); userEntity.Password = Tanshu.Common.Md5.Hash(txtPassword.Text.Trim(), "v2"); if (UserBI.ValidateUser(userEntity.Name, userEntity.Password)) return UserBI.ChangePassword(userEntity, Tanshu.Common.Md5.Hash(txtnewPassword.Text.Trim(), "v2")); else return false; } } }