Guest User

Untitled

a guest
Oct 19th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. unit usenha;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7. Dialogs, StdCtrls, jpeg, ExtCtrls, Inifiles, _libmysq, DB,
  8. ZAbstractRODataset, ZAbstractDataset, ZDataset, ZConnection, Grids,
  9. DBGrids, HashAlg_U, HashAlgMD5_U;
  10.  
  11. type
  12. TFormSenha = class(TForm)
  13. Panel1: TPanel;
  14. EdSenha: TEdit;
  15. Image1: TImage;
  16. Labsenha: TLabel;
  17. query_u: TZReadOnlyQuery;
  18. DataSource1: TDataSource;
  19. _md5: THashAlgMD5;
  20. query_uID: TIntegerField;
  21. query_uNOME: TStringField;
  22. query_uFUNCAO: TStringField;
  23. query_uLOGIN: TStringField;
  24. query_uSENHA: TStringField;
  25. query_uCONFERE: TIntegerField;
  26. query_uADM: TIntegerField;
  27. query_uATIVO: TIntegerField;
  28. procedure EdSenhaKeyPress(Sender: TObject; var Key: Char);
  29. procedure checa_senha;
  30. procedure FormCreate(Sender: TObject);
  31. procedure FormShow(Sender: TObject);
  32. private
  33. { Private declarations }
  34. public
  35. usuario_id: integer;
  36. usuario_nome: string;
  37. end;
  38.  
  39. var
  40. FormSenha: TFormSenha;
  41. senha: string;
  42. _senha : THashArray;
  43. usuario_excluir, usuario_processamento, usuario_notas, usuario_web, usuario_copiar, usuario_cad_usuario, usuario_cad_lotes: integer;
  44.  
  45.  
  46. implementation
  47.  
  48. uses uMain;
  49.  
  50. {$R *.dfm}
  51.  
  52. procedure TFormSenha.EdSenhaKeyPress(Sender: TObject; var Key: Char);
  53. begin
  54. case key of
  55. #27: begin
  56. application.terminate;
  57. close;
  58. end;
  59.  
  60. #13: checa_senha;
  61. end;
  62. end;
  63.  
  64. procedure TFormSenha.checa_senha;
  65.  
  66. var qtos,i:integer;
  67.  
  68. begin
  69.  
  70. _senha := _md5.HashString(edsenha.text);
  71. senha := _md5.hashtodisplay(_senha);
  72.  
  73. query_u.sql.clear;
  74. query_u.SQL.add('SELECT * from USUARIOS WHERE senha='+quotedstr(senha));
  75. query_u.Active := true;
  76.  
  77. if query_u.recordcount < 1 then begin
  78. labsenha.Caption := 'Senha Inválida';
  79. labsenha.visible := True;
  80. edsenha.text := '';
  81. exit;
  82. end;
  83.  
  84. if (not query_u.fieldbyname('ativo').AsInteger = 1) then begin
  85. labsenha.Caption := 'Esta conta ainda não foi ativada';
  86. labsenha.visible := True;
  87. edsenha.text := '';
  88. exit;
  89. end;
  90.  
  91.  
  92.  
  93. FormSenha.Close;
  94. if query_uid.AsInteger = 0 then Application.Terminate;
  95. usuario_id := query_uid.AsInteger;
  96.  
  97. { SETAR AS OPÇÕES DISPONÍVEIS }
  98. {
  99. if (query_u.fieldbyname('adm').AsInteger = 1) then FormMain.caduser.Visible := True else FormMain.caduser.Visible := False;
  100. if (query_u.fieldbyname('confere').AsInteger = 1) then FormMain.editaindice.Visible := True else FormMain.editaindice.Visible := False;
  101.  
  102. if (query_u.fieldbyname('financeiro').AsInteger = 1)then formmain.TabFinanc.Visible := True
  103. else formmain.TabNF.Visible := False;
  104.  
  105. if (query_u.fieldbyname('rh').AsInteger = 1)then formmain.TabContrato.Visible := True
  106. else formmain.TabContrato.Visible := False;
  107.  
  108. }
  109.  
  110. formMain.visible := True;
  111. Application.showmainform := True;
  112. end;
  113.  
  114.  
  115.  
  116. procedure TFormSenha.FormCreate(Sender: TObject);
  117. var
  118. AppIni: TIniFile;
  119. _host, _user, _pass, _db, digipath: string;
  120. tempcd, drivecd, _dbfile, dbfile, _pasta: string;
  121. begin
  122. AppIni := TIniFile.Create( ChangeFileExt( Application.ExeName, '.INI' ) );
  123.  
  124.  
  125. { ********* SESSAO MYSQL ***************}
  126. {
  127.  
  128.  
  129.  
  130. _dbfile := AppIni.ReadString( 'dat', 'dbfile', ' ');
  131. _host := AppIni.ReadString( 'dat', 'host', '');
  132.  
  133. _user := AppIni.ReadString( 'dat', 'user', 'root');
  134. _pass := AppIni.ReadString( 'dat', 'pass', '');
  135. _db := AppIni.ReadString( 'dat', 'db', 'lotes');
  136. _drive:= StrToInt(AppIni.ReadString( 'configura', 'drive', '0'));
  137. _pasta:= AppIni.ReadString( 'configura', 'pasta', '\imagens');
  138. _pastaenvelopes := AppIni.ReadString( 'configura', 'envelopes', '\imagens');
  139.  
  140. { ************ FIM SECAO MYSQL **************** }
  141.  
  142.  
  143.  
  144. { ********* SECAO FIREBIRD ***************}
  145. digipath := 'c:\temp\diginotas';
  146.  
  147. ForceDirectories(digipath);
  148.  
  149. tempcd := copy(AppIni.Filename,1,1);
  150. drivecd := tempcd[1];
  151.  
  152. dbfile := AppIni.ReadString( 'dat', 'dbfile', 'milenio.fdb');
  153. _host := AppIni.ReadString( 'dat', 'host', '');
  154.  
  155. _user := AppIni.ReadString( 'dat', 'user', 'SYSDBA');
  156. _pass := AppIni.ReadString( 'dat', 'pass', 'masterkey');
  157. _db := AppIni.ReadString( 'dat', 'db', digipath+'\'+dbfile);
  158.  
  159. if not FileExists (pchar(digipath+'\'+dbfile)) then begin
  160. copyfile(pchar(dbfile), pchar(digipath+ '\'+ dbfile), false);
  161. FileSetAttr(digipath+ '\'+ dbfile, FaArchive);
  162. end;
  163.  
  164. { ************ FIM SECAO FIREBIRD **************** }
  165.  
  166.  
  167. formmain.mysql1.connected := False;
  168. formmain.mysql1.User := _user;
  169. formmain.mysql1.Password := _pass;
  170. formmain.mysql1.HostName := _host;
  171. formmain.mysql1.Database := _db;
  172.  
  173. formmain.mysql1.connect;
  174.  
  175.  
  176. end;
  177.  
  178. procedure TFormSenha.FormShow(Sender: TObject);
  179. begin
  180. senha:='';
  181. Labsenha.Visible := False;
  182. Edsenha.SetFocus;
  183. end;
  184.  
  185. end.
Add Comment
Please, Sign In to add comment