115 lines
4.2 KiB
C#
115 lines
4.2 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraEditors;
|
|
using LFP_Manager.DataStructure;
|
|
using LFP_Manager.Function;
|
|
|
|
namespace LFP_Manager.Forms
|
|
{
|
|
public partial class FmxChangePassword : XtraForm
|
|
{
|
|
private CommConfig Config;
|
|
|
|
public FmxChangePassword(CommConfig aConfig)
|
|
{
|
|
InitializeComponent();
|
|
Config = aConfig;
|
|
|
|
cbPasswordType.Properties.Items.Clear();
|
|
cbPasswordType.Properties.Items.Add("Anti-Theft Enable Password");
|
|
cbPasswordType.Properties.Items.Add("Anti-Theft Disable Password");
|
|
cbPasswordType.SelectedIndex = 0;
|
|
}
|
|
|
|
private void CbPasswordType_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
teCurrentPassword.Text = string.Empty;
|
|
teNewPassword.Text = string.Empty;
|
|
teConfirmPassword.Text = string.Empty;
|
|
teCurrentPassword.Focus();
|
|
}
|
|
|
|
private void CeShowPassword_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
char pChar = ceShowPassword.Checked ? '\0' : '*';
|
|
teCurrentPassword.Properties.PasswordChar = pChar;
|
|
teNewPassword.Properties.PasswordChar = pChar;
|
|
teConfirmPassword.Properties.PasswordChar = pChar;
|
|
}
|
|
|
|
private void BtnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.DialogResult = DialogResult.Cancel;
|
|
this.Close();
|
|
}
|
|
|
|
private void BtnOk_Click(object sender, EventArgs e)
|
|
{
|
|
string currentInput = teCurrentPassword.Text;
|
|
string newInput = teNewPassword.Text;
|
|
string confirmInput = teConfirmPassword.Text;
|
|
|
|
bool isEnablePw = (cbPasswordType.SelectedIndex == 0);
|
|
string actualCurrentPw = isEnablePw ? Config.EnablePassword : Config.DisablePassword;
|
|
|
|
// 1. 현재 비밀번호 확인
|
|
if (currentInput != actualCurrentPw)
|
|
{
|
|
MessageBox.Show("Current password is incorrect.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
teCurrentPassword.Focus();
|
|
teCurrentPassword.SelectAll();
|
|
return;
|
|
}
|
|
|
|
// 2. 새 비밀번호 공백 확인
|
|
if (string.IsNullOrWhiteSpace(newInput))
|
|
{
|
|
MessageBox.Show("New password cannot be empty.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
teNewPassword.Focus();
|
|
return;
|
|
}
|
|
|
|
// 3. 새 비밀번호와 현재 비밀번호 동일 여부 확인
|
|
if (newInput == actualCurrentPw)
|
|
{
|
|
MessageBox.Show("New password cannot be the same as current password.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
teNewPassword.Focus();
|
|
teNewPassword.SelectAll();
|
|
return;
|
|
}
|
|
|
|
// 4. 새 비밀번호 일치 확인
|
|
if (newInput != confirmInput)
|
|
{
|
|
MessageBox.Show("New password and confirm password do not match.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
teConfirmPassword.Focus();
|
|
teConfirmPassword.SelectAll();
|
|
return;
|
|
}
|
|
|
|
// 5. 비밀번호 업데이트 및 ini 파일 저장 (자동 암호화)
|
|
if (isEnablePw)
|
|
{
|
|
Config.EnablePassword = newInput;
|
|
}
|
|
else
|
|
{
|
|
Config.DisablePassword = newInput;
|
|
}
|
|
|
|
try
|
|
{
|
|
csIniControlFunction.IniSave(Application.ExecutablePath, Config);
|
|
string pwTypeName = isEnablePw ? "Anti-Theft Enable Password" : "Anti-Theft Disable Password";
|
|
MessageBox.Show(string.Format("{0} has been changed successfully.", pwTypeName), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(string.Format("Failed to save password: {0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|