narsil/Tanshu.Accounts.PointOfSale/User Management/ChangePassword.cs

65 lines
2.1 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
using System.Windows.Forms;
using Tanshu.Accounts.BI;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Helpers;
namespace Tanshu.Accounts.PointOfSale
{
public partial class ChangePassword : Form
{
public ChangePassword()
{
InitializeComponent();
}
private void ChangePassword_Load(object sender, EventArgs e)
{
txtUsername.Text = CurrentUser.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()
{
UserBO userEntity = new UserBO();
userEntity.Name = txtUsername.Text.Trim();
userEntity.Password = Tanshu.Common.Md5.Hash(txtPassword.Text.Trim(), "Salt");
if (new MembershipBI().ValidateUser(userEntity.Name, userEntity.Password))
return new UserBI().ChangePassword(userEntity, Tanshu.Common.Md5.Hash(txtnewPassword.Text.Trim(), "Salt"));
else
return false;
}
}
}