unit ChangePswUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, Db, DBClient, ExtCtrls;
type
TChangePswFrm = class(TForm)
GroupBox1: TGroupBox;
lblUserName: TLabel;
edtPsw1: TEdit;
edtPsw2: TEdit;
lblPsw: TLabel;
bbtnOk: TBitBtn;
bbtnCancel: TBitBtn;
lblCurrPsw: TLabel;
edtCurrPsw: TEdit;
Bevel1: TBevel;
cdsOperator: TClientDataSet;
procedure bbtnOkClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
function CheckCurrPsw: boolean;
public
{ Public declarations }
end;
type TDesStr = array[0..16] of char;
function StrEndes(str: TDesStr;strout: TDesStr):integer ;stdcall;
external 'desdll.dll';
var
ChangePswFrm: TChangePswFrm;
implementation
uses PublicUnit, dmCustUnit;
{$R *.DFM}
var
count:integer;
//user can input error 3 times
procedure TChangePswFrm.bbtnOkClick(Sender: TObject);
var
InitPsw,TmpDes:TDesStr;
i,DesLen: integer;
ok: boolean;
bytePsw:array of byte;
DesPsw:variant;
//StrEndes: TStrEndes;
begin
if Trim(edtCurrPsw.Text)='' then
begin
Application.MessageBox('Current password is null,Please input it!','Warning',MB_OK+MB_ICONWARNING);
edtCurrPsw.SetFocus;
ModalResult := mrNone //this form can not be closed
end
else
if Trim(edtPsw1.Text)='' then
begin
Application.MessageBox('New password is null,Please input the new password!','Warning',MB_OK+MB_ICONWARNING);
edtPsw1.SetFocus;
ModalResult := mrNone //this form can not be closed
end
else
if Length(Trim(edtPsw1.Text)) < 6 then
begin
Application.MessageBox('Password cannot less then
6 character,Please re_input the new password!','Warning',MB_OK+MB_ICONWARNING);
edtPsw1.SetFocus;
ModalResult := mrNone //this form can not be closed
end
else
if Trim(edtPsw2.Text)='' then
begin
Application.MessageBox('New password is null,Please input the new password again!','Warning',MB_OK+MB_ICONWARNING);
edtPsw2.SetFocus;
ModalResult := mrNone //this form can not be closed
end
else
if Trim(edtPsw1.Text) <> Trim(edtPsw2.Text) then
begin
Application.MessageBox('The second password not match the first password, Please re-input it!','Warning',MB_OK+MB_ICONWARNING);
edtPsw2.SetFocus;
ModalResult := mrNone //this form can not be closed
end
else
if count=4 then
begin
Application.MessageBox('Sorry! You cannot change your password, you have inputed 3 times wrong password!','Warning',MB_OK+MB_ICONWARNING);
ModalResult := mrOK
end
else
if not CheckCurrPsw then
ModalResult := mrNone //this form can not be closed
else
begin
ok := False;
setLength(bytePsw,16);
//DesEn the customer password
StrCopy(InitPsw,Pchar(edtPsw1.Text));
DesLen := StrEndes(InitPsw, TmpDes);
for i := 0 to DesLen - 1do
bytePsw := Byte(TmpDes);
DesPsw:=bytePsw;
// dmCustInfo.dcomConn.AppServer.UpdatePsw(dbeOperatorID.Text,DesPsw);
if not cdsOperator.Active then
cdsOperator.Active := True;
if not cdsOperator.Locate('OPERATOR_ID', OperatorID, []) then
Application.MessageBox('Try to save the change to database failed, please change it later!','Warning',MB_OK+MB_ICONWARNING)
else
begin
try
dmCustInfo.dcomConn.AppServer.UpdatePsw(OperatorID,DesPsw);
ok := True
except
Application.MessageBox('Try to save the change to database failed, please change it later!','Warning',MB_OK+MB_ICONWARNING);
cdsOperator.RevertRecord;
ok := False
end
end;
if ok then
cdsOperator.Active := False
end
end;
procedure TChangePswFrm.FormCreate(Sender: TObject);
begin
count := 1;
end;
function TChangePswFrm.CheckCurrPsw: boolean;
var
TmpPsw, InitPsw:TDesStr;
DesLen: integer;
begin
//DesEn the customer password
StrCopy(InitPsw,Pchar(edtCurrPsw.Text));
DesLen := StrEndes(InitPsw, TmpPsw);
TmpPsw[DesLen] := #0;
if StrComp(PChar(string(UserPsw)),PChar(string(TmpPsw)))<>0 then
begin
Application.MessageBox('Invalid Password, input it again!','Warning',MB_OK+MB_ICONWARNING);
count := count + 1;
edtCurrPsw.SetFocus;
Result := False;
end
else
Result := True
end;
end.