Skip to content

Commit b246316

Browse files
Merge pull request #8 from BastianTeufel-GTR/master
Added suppot for 2b Bcrypt Hash type and increased Cost to 12
2 parents 280a434 + 4e7631c commit b246316

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/BCrypt.Consts.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface
77
const
88
BCRYPT_SALT_LEN = 16;
99
BLOWFISH_NUM_ROUNDS = 16;
10-
BCRYPT_DEFAULT_COST = 10;
10+
BCRYPT_DEFAULT_COST = 12;
1111

1212
PBoxOrg: array [0 .. 17] of DWORD = (
1313
$243f6a88, $85a308d3, $13198a2e, $03707344, $a4093822, $299f31d0, $082efa98,

src/BCrypt.Core.pas

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,10 @@ function TBCryptImpl.FormatPasswordHash(const ASalt, AHash: TBytes; ACost: Byte;
219219
case AHashType of
220220
THashType.BSD:
221221
LPrefix := '2a';
222-
THashType.PHP, THashType.Default:
222+
THashType.PHP :
223223
LPrefix := '2y';
224+
THashType.Default:
225+
LPrefix := '2b';
224226
end;
225227
LSalt := BsdBase64Encode(ASalt, Length(ASalt));
226228
LHash := BsdBase64Encode(AHash, Length(MagicText) * 4 - 1);
@@ -338,11 +340,13 @@ function TBCryptImpl.Crypt(const APassword: UTF8String; const ASalt: string; ACo
338340

339341
function TBCryptImpl.ResolveHashType(const AHashType: string): THashType;
340342
begin
341-
case AnsiIndexStr(AHashType, ['$2y$', '$2a$']) of
343+
case AnsiIndexStr(AHashType, ['$2y$', '$2a$','$2b$']) of
342344
0:
343345
Result := THashType.PHP;
344346
1:
345347
Result := THashType.BSD;
348+
2:
349+
Result := THashType.Default; // added as being current default
346350
else
347351
Result := THashType.Unknown;
348352
end;

src/BCrypt.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ implementation
2222

2323
class function TBCrypt.GenerateHash(const APassword: string): string;
2424
begin
25-
Result := TBCryptImpl.New.GenerateHash(UTF8String(APassword), THashType.BSD, BCRYPT_DEFAULT_COST);
25+
Result := TBCryptImpl.New.GenerateHash(UTF8String(APassword), THashType.Default, BCRYPT_DEFAULT_COST);
2626
end;
2727

2828
class function TBCrypt.GenerateHash(const APassword: string; ACost: Byte): string;

0 commit comments

Comments
 (0)