home *** CD-ROM | disk | FTP | other *** search
/ Chip: Shareware for Win 95 / Chip-Shareware-Win95.bin / ostatni / delphi / delphi2 / wowsrc.exe / NEWPASS.PAS < prev    next >
Pascal/Delphi Source File  |  1995-09-14  |  3KB  |  92 lines

  1. unit Newpass;
  2.  
  3. interface
  4.  
  5. uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls, StdCtrls,
  6.   Buttons, Dialogs, IniFiles;
  7.  
  8. type
  9.   TChPwd = class(TForm)
  10.     Label1: TLabel;
  11.     OldPwd: TEdit;
  12.     Label2: TLabel;
  13.     NewPwd: TEdit;
  14.     Label3: TLabel;
  15.     Rpwd: TEdit;
  16.     Ok: TBitBtn;
  17.     Cancel: TBitBtn;
  18.     procedure OldPwdChange(Sender: TObject);
  19.     procedure OkClick(Sender: TObject);
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure FormActivate(Sender: TObject);
  22.   private
  23.     Loading : Boolean;
  24.     { Private declarations }
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. var
  30.   ChPwd: TChPwd;
  31.  
  32. implementation
  33.  
  34. {$R *.DFM}
  35.  
  36. Uses WinPwd, Globals;
  37.  
  38. procedure TChPwd.OldPwdChange(Sender: TObject);            { Old is changing }
  39. begin
  40.   if Not NewPwd.Enabled then begin                         { If New is NOT enabled }
  41.     NewPwd.Enabled := True;                                { Enable New Password }
  42.     Rpwd.Enabled := True;                                  { Enable Retypr }
  43.     end;
  44. end;
  45.  
  46. procedure TChPwd.OkClick(Sender: TObject);                 { Ok }
  47. Var
  48.   Op,Np,Rp : String;                                       { Local Vars }
  49.   Ini : TiniFile;                                          { For Wow.Ini }
  50. begin
  51.   if NewPwd.Enabled then Begin                             { If New is enabled }
  52.     Op := OldPwd.Text;                                     { Get the Old Password }
  53.     EncryptString(Op);                                     { Encrypt it }
  54.     if Op <> Pwd then begin                                { Check against Current Password }
  55.       MessageDlg('Old password is not correct',
  56.                  mtError,[mbOk],0);                        { Not the same }
  57.       exit;                                                { Try again }
  58.       end;
  59.     end;
  60.  
  61.   Np := NewPwd.Text;                                       { Get the New Password }
  62.   Rp := Rpwd.Text;                                         { Get the Retyped Password }
  63.   if Np <> Rp then begin                                   { If Not Same }
  64.     MessageDlg('New and retyped password are not the same',
  65.                mtError,[mbOk],0);                          { Err Message }
  66.     exit;                                                  { Bye Bye }
  67.     end;
  68.   EncryptString(Np);                                       { Encrypt the Password }
  69.   Ini := TIniFile.Create('Wow.Ini');                   { Open Wow.Ini }
  70.   Ini.WriteString('ScreenSaver','Password',Np);            { Save the Password }
  71.   Ini.Free;                                                { Close INI and Free }
  72.   Close;                                                   { Bye Bye }
  73. end;
  74.  
  75. procedure TChPwd.FormCreate(Sender: TObject);
  76. begin
  77.   Loading := True;                                         { Set Loading Flag }
  78. end;
  79.  
  80. procedure TChPwd.FormActivate(Sender: TObject);
  81. begin
  82.   if Loading then begin                                    { If Loading }
  83.     Loading := False;                                      { Reset Flag }
  84.     if OldPwd.Enabled then                                 { If Old is enabled }
  85.       OldPwd.SetFocus                                      { Set focus }
  86.     else
  87.       NewPwd.SetFocus;                                     { Else set focus to New }
  88.     end;
  89. end;
  90.  
  91. end.
  92.