home *** CD-ROM | disk | FTP | other *** search
/ Chip: Shareware for Win 95 / Chip-Shareware-Win95.bin / ostatni / delphi / delphi2 / wowsrc.exe / GETPASS.PAS < prev    next >
Pascal/Delphi Source File  |  1995-03-25  |  6KB  |  141 lines

  1. unit Getpass;
  2.  
  3. interface
  4.  
  5. uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls,
  6.      StdCtrls, Buttons, ExtCtrls,SysUtils, Dialogs;
  7.  
  8. type
  9.   TWpwd = class(TForm)
  10.     L: TLabel;
  11.     L2: TLabel;
  12.     WinPwd: TEdit;
  13.     Ok: TBitBtn;
  14.     Cancel: TBitBtn;
  15.     TicToc: TTimer;
  16.     procedure OkClick(Sender: TObject);
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure CancelClick(Sender: TObject);
  19.     procedure TicTocTimer(Sender: TObject);
  20.     procedure WinPwdChange(Sender: TObject);
  21.   private
  22.     Loading : Boolean;
  23.     { Private declarations }
  24.   public
  25.     PwdOk : Boolean;
  26.  
  27.     { Public declarations }
  28.   end;
  29.  
  30. var
  31.   Wpwd: TWpwd;
  32.  
  33. {$IFDEF NOVELL}
  34.  
  35. { Verify a password against a bindery object }
  36. Function VerifyBinderyObjectPassword(UserName : PChar;
  37.                                     BinType  : Integer;
  38.                                     PassWord : PChar) : Integer;
  39. {$ENDIF}
  40. implementation
  41.  
  42. {$R *.DFM}
  43.  
  44. Uses WinPwd, Globals;
  45.  
  46. {$IFDEF NOVELL}
  47. Function VerifyBinderyObjectPassword; external 'NWNETAPI';
  48. {$ENDIF}
  49.  
  50.  
  51. procedure TWpwd.OkClick(Sender: TObject);
  52. Var
  53.   P      : String;                                         { Local Password }
  54.   iRc    : Integer;                                        { Novell return code }
  55.   szUpwd : Array [0..50] of char;                          { Null term buffer }
  56. begin
  57.   PwdOk := True;                                           { assume the passwords Ok }
  58.   P := UpperCase(WinPwd.Text);                             { Uppercase the password they typed }
  59.   if PwdType = 1 then Begin                                { If this is a WINDOWS password }
  60.     EncryptString(P);                                      { Encrypt it }
  61.     if Pwd[0] <> Chr(0) then begin                         { if worth checking }
  62.       PwdOk := (Pwd = P);                                  { Set validity }
  63.       if Not PwdOk then PwdOk := (OverPwd = P);            { if not ok check the Override password }
  64.       if Not PwdOk then begin                              { if that's not it then bomb out }
  65.         MessageDlg('Incorrect password. ' +
  66.          'Check your screen saver password and try again',
  67.            mtError,[mbok],0);                              { Suitable error message }
  68.         WinPwd.SelectAll;                                  { select entire password }
  69.         WinPwd.SetFocus;                                   { Reset the focus }
  70.         end
  71.       else begin                                           { Else PWD ok }
  72.         Close;                                             { Shut down }
  73.         Exit;                                              { Melt Down }
  74.         end;
  75.       end;
  76.     end
  77.   else begin
  78. {$IFDEF NOVELL}
  79.     Screen.Cursor := crHourGlass;                          { Start waiting }
  80.     StrPCopy(szUpwd,P);                                    { Grab copy of password }
  81.     iRc := VerifyBinderyObjectPassword(szUserName,
  82.                                        1,
  83.                                        szUpwd);            { Verify against USER login name }
  84.     if Irc > 0 then                                        { if the above failes try the SUPERVISOR passord }
  85.       iRc := VerifyBinderyObjectPassword('SUPERVISOR',
  86.                                        1,
  87.                                        szUpwd);            { Ask Novell }
  88.     Screen.Cursor := crDefault;
  89. {$ELSE}
  90.     Irc := 0;
  91. {$ENDIF}
  92.     if Irc > 0 then begin                                  { if all failed }
  93.       PwdOk := False;                                      { Set Return }
  94.       MessageDlg('Incorrect password. ' +
  95.              'Check your NETWORK password and try again',
  96.              mtError,[mbok],0);                            { Display a message }
  97.  
  98.       WinPwd.SelectAll;                                    { Select the entire password }
  99.       WinPwd.SetFocus;                                     { set focus }
  100.       exit;                                                { ta ta }
  101.       end
  102.     else
  103.       Close;                                               { Pwd Ok bye bye screensaver }
  104.     end;
  105. end;
  106.  
  107. procedure TWpwd.FormCreate(Sender: TObject);
  108. begin
  109.   if PwdType = 2 then Begin                                { If a novell password }
  110.     if szUserName[0] = #0 then                             { check there is a user name }
  111.       if PwdType = 2 then PwdType := 1                     { No name so use the windows password, not on NET }
  112.     end;
  113.   if PwdType = 2 then                                      { If a network password }
  114.     L.Caption := 'You are currently logged into ' +
  115.                  StrPas(szFsName) + ' as ' +
  116.                  StrPas(szUserName) +
  117.                  '. Please enter your NETWORK password';   { Set the caption to tell about server and name }
  118.   PwdOk := False;
  119. end;
  120.  
  121. procedure TWpwd.CancelClick(Sender: TObject);
  122. begin
  123.   PwdOk := False;                                          { Bombed out so not got password }
  124.   Close;                                                   { Bye Bye }
  125. end;
  126.  
  127. procedure TWpwd.TicTocTimer(Sender: TObject);              { timer fires after 10 secs }
  128. begin
  129.   PwdOk := False;                                          { No password }
  130.   Close;                                                   { Ta Ta }
  131. end;
  132.  
  133. procedure TWpwd.WinPwdChange(Sender: TObject);             { User is typing }
  134. begin
  135.   TicToc.Enabled := False;                                 { Reset timer }
  136.   TicToc.Enabled := True;                                  { Start it }
  137. end;
  138.  
  139. begin
  140. end.
  141.