ab56a9bcf7
SVN-Revision: r240
224 lines
8.8 KiB
C#
224 lines
8.8 KiB
C#
/******************************
|
|
* 说明:强制修改密码
|
|
* 创建人:龚宇超
|
|
* 创建日期:2017-08-12
|
|
* 修改人:
|
|
* 修改日期:
|
|
* 修改备注:
|
|
* 版本:1.0.0.0
|
|
******************************/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraEditors;
|
|
using Lskj.Control;
|
|
using Lskj.Data;
|
|
using Lskj.Business;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Model;
|
|
using Lskj.Util;
|
|
using System.Text.RegularExpressions;
|
|
using Lskj.Core;
|
|
|
|
namespace Lskj.PubModulePrivate
|
|
{
|
|
/// <summary>
|
|
/// 强制修改密码
|
|
/// </summary>
|
|
public partial class FrmPassword : BaseForm
|
|
{
|
|
private bool isOldPassword = false;
|
|
private string oldPassword = string.Empty;
|
|
Regex regex = new Regex(@"(?=.*[0-9]) #必须包含数字
|
|
(?=.*[a-zA-Z]) #必须包含小写或大写字母
|
|
.{8,18} #至少6个字符,最多18个字符
|
|
", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace); //(?=.*[^a-zA-Z0-9]) #必须包含符号
|
|
public FrmPassword()
|
|
{
|
|
InitializeComponent();
|
|
this.txtPassOld.KeyDown += new KeyEventHandler(OnKeyDown);
|
|
this.txtPassAfter.KeyDown += new KeyEventHandler(OnKeyDown);
|
|
this.txtPassBefore.KeyDown += new KeyEventHandler(OnKeyDown);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:界面加载时</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-12 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void FrmPassword_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
int keyHandle = ERPInfo.Instance.keyHandles[0];
|
|
int uPin1 = Convert.ToInt32("0x987F6BCD", 16);
|
|
int uPin2 = Convert.ToInt32("0xE193C5B2", 16);
|
|
int uPin3 = Convert.ToInt32("0xD507CC28", 16);
|
|
int uPin4 = Convert.ToInt32("0x4B125AF6", 16);
|
|
int rtn = SmartX1Api.SmartX1Open(keyHandle, uPin1, uPin2, uPin3, uPin4);
|
|
if (rtn == 0)
|
|
{
|
|
byte[] readBuffer = new byte[256];
|
|
int add = 0;
|
|
int len = 256;
|
|
int readPageRtn = SmartX1Api.SmartX1ReadPage(keyHandle, 0, add, ref len, readBuffer);
|
|
if (readPageRtn == 0)
|
|
{
|
|
this.oldPassword = Encoding.Default.GetString(readBuffer).Replace("\0", "");
|
|
if (oldPassword.Equals(ERPInfo.Instance.dogVerifyPasswordDefault) || string.IsNullOrWhiteSpace(oldPassword.Replace("\0", "")))
|
|
{
|
|
this.labelControl1.Visible = false;
|
|
this.txtPassOld.Visible = false;
|
|
this.isOldPassword = false;
|
|
}
|
|
else
|
|
{
|
|
this.isOldPassword = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("U盾数据获取失败,请重试或联系管理员");
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("U盾数据获取失败,请重试或联系管理员");
|
|
return;
|
|
}
|
|
SmartX1Api.SmartX1Close(keyHandle);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:修改保存</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-12 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
string pass_old = txtPassOld.Text.Trim();
|
|
string pass_before = txtPassBefore.Text.Trim();
|
|
string pass_after = txtPassAfter.Text.Trim();
|
|
if (this.isOldPassword && (string.IsNullOrWhiteSpace(pass_old) || !SHAHelper.EncryptPassword(pass_old).Equals(this.oldPassword)))
|
|
{
|
|
MessageUtil.Show("旧密码验证错误");
|
|
return;
|
|
}
|
|
if (string.IsNullOrWhiteSpace(pass_before) || string.IsNullOrWhiteSpace(pass_after))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.PasswordNotNull);
|
|
return;
|
|
}
|
|
if (!pass_before.Equals(pass_after))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.PasswordInconformity);
|
|
return;
|
|
}
|
|
// 验证密码标准
|
|
if (!regex.IsMatch(pass_after))//SystemInfo.Instance.VerfyPasswordStrength
|
|
{
|
|
MessageUtil.Show("密码不符合要求!");
|
|
return;
|
|
}
|
|
int keyHandle = ERPInfo.Instance.keyHandles[0];
|
|
int uPin1 = Convert.ToInt32("0x987F6BCD", 16);
|
|
int uPin2 = Convert.ToInt32("0xE193C5B2", 16);
|
|
int uPin3 = Convert.ToInt32("0xD507CC28", 16);
|
|
int uPin4 = Convert.ToInt32("0x4B125AF6", 16);
|
|
int rtn = SmartX1Api.SmartX1Open(keyHandle, uPin1, uPin2, uPin3, uPin4);
|
|
if (rtn == 0)
|
|
{
|
|
int add = 0;
|
|
int len = 256;
|
|
byte[] writeBuffer = Encoding.Default.GetBytes(SHAHelper.EncryptPassword(pass_after));
|
|
int writeRtn = SmartX1Api.SmartX1WritePage(keyHandle, 0, add, len, writeBuffer);
|
|
if (writeRtn == 0)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.PasswordUpdateSuccess);
|
|
this.DialogResult = DialogResult.OK;
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("密码修改失败,请检查U盾状态后重试或联系管理员");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("U盾数据获取失败,请重试或联系管理员");
|
|
return;
|
|
}
|
|
SmartX1Api.SmartX1Close(keyHandle);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show("修改密码出错!" + Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 按键切换
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
TextBox textBox = (TextBox)sender;
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
if (textBox == this.txtPassOld)
|
|
{
|
|
this.txtPassBefore.Focus();
|
|
}
|
|
else if (textBox == this.txtPassBefore)
|
|
{
|
|
|
|
this.txtPassAfter.Focus();
|
|
}
|
|
else
|
|
{
|
|
btnSave_Click(sender, null);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:取消修改</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-12 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void btnExit_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|