using System; using System.Windows.Forms; using Tanshu.Accounts.Repository; using Tanshu.Accounts.Contracts; using Tanshu.Accounts.Helpers; using Tanshu.Accounts.Entities.Auth; using Tanshu.Common.KeyboardControl; namespace Tanshu.Accounts.PointOfSale { public partial class ChangePassword : Form { IKeyboardControl keyboardControl; public ChangePassword(IKeyboardControl keyboardControl) { InitializeComponent(); this.keyboardControl = keyboardControl; var control = keyboardControl as UserControl; if (control != null) { control.Location = new System.Drawing.Point(6, 140); var border = (this.Width - this.ClientSize.Width) / 2; var titlebarHeight = this.Height - this.ClientSize.Height - (2 * border); this.Controls.Add(control); this.Width = 6 + control.Width + 6 + (border * 2); this.Height = titlebarHeight + 140 + control.Height + 6 + (border * 2); } } 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; } } }