Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed Feb 14, 2020
1 parent 8278211 commit 3b839c8
Show file tree
Hide file tree
Showing 9 changed files with 1,942 additions and 0 deletions.
19 changes: 19 additions & 0 deletions samples/Samples.dpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
program Samples;

uses
Vcl.Forms,
Samples.Main in 'src\Samples.Main.pas' {FrmSamples},
BCrypt.Core in '..\src\BCrypt.Core.pas',
BCrypt.Intf in '..\src\BCrypt.Intf.pas',
BCrypt.Types in '..\src\BCrypt.Types.pas',
BCrypt.Consts in '..\src\BCrypt.Consts.pas',
BCrypt in '..\src\BCrypt.pas';

{$R *.res}

begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TFrmSamples, FrmSamples);
Application.Run;
end.
846 changes: 846 additions & 0 deletions samples/Samples.dproj

Large diffs are not rendered by default.

276 changes: 276 additions & 0 deletions samples/src/Samples.Main.dfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
object FrmSamples: TFrmSamples
Left = 0
Top = 0
BorderStyle = bsSingle
Caption = 'BCrypt'
ClientHeight = 226
ClientWidth = 649
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object pclBCrypt: TPageControl
Left = 0
Top = 0
Width = 649
Height = 226
ActivePage = tabNeedsRehash
Align = alClient
TabOrder = 0
object tabGenerate: TTabSheet
Caption = 'Generate hash'
ExplicitWidth = 281
ExplicitHeight = 165
object Panel1: TPanel
Left = 0
Top = 0
Width = 641
Height = 198
Align = alClient
BevelOuter = bvNone
TabOrder = 0
ExplicitLeft = 232
ExplicitTop = 200
ExplicitWidth = 185
ExplicitHeight = 41
object edtPassword: TLabeledEdit
Left = 12
Top = 23
Width = 534
Height = 21
EditLabel.Width = 50
EditLabel.Height = 13
EditLabel.Caption = 'Password:'
TabOrder = 0
end
object btnGenerate: TButton
Left = 552
Top = 21
Width = 75
Height = 25
Caption = 'Generate'
TabOrder = 1
OnClick = btnGenerateClick
end
object mmBCrypt: TMemo
Left = 12
Top = 52
Width = 615
Height = 137
ReadOnly = True
TabOrder = 2
end
end
end
object tabCompare: TTabSheet
Caption = 'Compare hash'
ImageIndex = 1
ExplicitLeft = 0
ExplicitTop = 28
object lblCompareTrue: TLabel
Left = 93
Top = 114
Width = 26
Height = 13
Caption = 'True'
Font.Charset = DEFAULT_CHARSET
Font.Color = clGreen
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
Visible = False
end
object lblCompareFalse: TLabel
Left = 93
Top = 114
Width = 29
Height = 13
Caption = 'False'
Font.Charset = DEFAULT_CHARSET
Font.Color = clMaroon
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
Visible = False
end
object edtPasswordCompare: TLabeledEdit
Left = 12
Top = 23
Width = 613
Height = 21
EditLabel.Width = 50
EditLabel.Height = 13
EditLabel.Caption = 'Password:'
TabOrder = 0
end
object edtHash: TLabeledEdit
Left = 12
Top = 71
Width = 613
Height = 21
EditLabel.Width = 28
EditLabel.Height = 13
EditLabel.Caption = 'Hash:'
TabOrder = 1
end
object btnCompare: TButton
Left = 12
Top = 109
Width = 75
Height = 25
Caption = 'Compare'
TabOrder = 2
OnClick = btnCompareClick
end
end
object tabHashInfo: TTabSheet
Caption = 'Get hash info'
ImageIndex = 2
ExplicitLeft = 0
ExplicitTop = 28
object Label1: TLabel
Left = 12
Top = 64
Width = 26
Height = 13
Caption = 'Info:'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
end
object Label2: TLabel
Left = 12
Top = 83
Width = 28
Height = 13
Caption = 'Type:'
end
object Label3: TLabel
Left = 12
Top = 102
Width = 26
Height = 13
Caption = 'Cost:'
end
object Label4: TLabel
Left = 16
Top = 121
Width = 22
Height = 13
Caption = 'Salt:'
end
object Label5: TLabel
Left = 12
Top = 140
Width = 28
Height = 13
Caption = 'Hash:'
end
object lblType: TLabel
Left = 46
Top = 83
Width = 3
Height = 13
end
object lblCost: TLabel
Left = 46
Top = 102
Width = 3
Height = 13
end
object lblSalt: TLabel
Left = 46
Top = 121
Width = 3
Height = 13
end
object lblHash: TLabel
Left = 46
Top = 140
Width = 3
Height = 13
end
object edtHashInfo: TLabeledEdit
Left = 12
Top = 23
Width = 534
Height = 21
EditLabel.Width = 28
EditLabel.Height = 13
EditLabel.Caption = 'Hash:'
TabOrder = 0
end
object btnGetHashInfo: TButton
Left = 552
Top = 21
Width = 75
Height = 25
Caption = 'Get'
TabOrder = 1
OnClick = btnGetHashInfoClick
end
end
object tabNeedsRehash: TTabSheet
Caption = 'Needs rehash'
ImageIndex = 3
object lblNeedsRehashTrue: TLabel
Left = 93
Top = 55
Width = 26
Height = 13
Caption = 'True'
Font.Charset = DEFAULT_CHARSET
Font.Color = clGreen
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
Visible = False
end
object lblNeedsRehashFalse: TLabel
Left = 93
Top = 55
Width = 29
Height = 13
Caption = 'False'
Font.Charset = DEFAULT_CHARSET
Font.Color = clMaroon
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
Visible = False
end
object edtNeedsRehash: TLabeledEdit
Left = 12
Top = 23
Width = 613
Height = 21
EditLabel.Width = 28
EditLabel.Height = 13
EditLabel.Caption = 'Hash:'
TabOrder = 0
end
object btnNeedsRehash: TButton
Left = 12
Top = 50
Width = 75
Height = 25
Caption = 'Check'
TabOrder = 1
OnClick = btnNeedsRehashClick
end
end
end
end
88 changes: 88 additions & 0 deletions samples/src/Samples.Main.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
unit Samples.Main;

interface

uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms,
Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.ComCtrls;

type
TFrmSamples = class(TForm)
pclBCrypt: TPageControl;
tabGenerate: TTabSheet;
tabCompare: TTabSheet;
Panel1: TPanel;
edtPassword: TLabeledEdit;
btnGenerate: TButton;
mmBCrypt: TMemo;
edtPasswordCompare: TLabeledEdit;
edtHash: TLabeledEdit;
btnCompare: TButton;
lblCompareTrue: TLabel;
lblCompareFalse: TLabel;
tabHashInfo: TTabSheet;
edtHashInfo: TLabeledEdit;
btnGetHashInfo: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
lblType: TLabel;
lblCost: TLabel;
lblSalt: TLabel;
lblHash: TLabel;
tabNeedsRehash: TTabSheet;
edtNeedsRehash: TLabeledEdit;
btnNeedsRehash: TButton;
lblNeedsRehashTrue: TLabel;
lblNeedsRehashFalse: TLabel;
procedure btnGenerateClick(Sender: TObject);
procedure btnCompareClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btnGetHashInfoClick(Sender: TObject);
procedure btnNeedsRehashClick(Sender: TObject);
end;

var
FrmSamples: TFrmSamples;

implementation

{$R *.dfm}

uses BCrypt, BCrypt.Types, System.TypInfo;

procedure TFrmSamples.btnCompareClick(Sender: TObject);
begin
lblCompareTrue.Visible := TBCrypt.CompareHash(edtPasswordCompare.Text, edtHash.Text);
lblCompareFalse.Visible := not lblCompareTrue.Visible;
end;

procedure TFrmSamples.btnGenerateClick(Sender: TObject);
begin
mmBCrypt.Lines.Add(TBCrypt.GenerateHash(edtPassword.Text));
end;

procedure TFrmSamples.btnGetHashInfoClick(Sender: TObject);
var
LHashInfo: THashInfo;
begin
LHashInfo := TBCrypt.GetHashInfo(edtHashInfo.Text);
lblCost.Caption := IntToStr(LHashInfo.Cost);
lblSalt.Caption := LHashInfo.Salt;
lblHash.Caption := LHashInfo.Hash;
lblType.Caption := GetEnumName(TypeInfo(THashType), Integer(LHashInfo.&Type));
end;

procedure TFrmSamples.btnNeedsRehashClick(Sender: TObject);
begin
lblNeedsRehashTrue.Visible := TBCrypt.NeedsRehash(edtNeedsRehash.Text);
lblNeedsRehashFalse.Visible := not lblNeedsRehashTrue.Visible;
end;

procedure TFrmSamples.FormShow(Sender: TObject);
begin
pclBCrypt.ActivePage := tabGenerate;
end;

end.
Loading

0 comments on commit 3b839c8

Please sign in to comment.