android - Multi-device Bcrypt library for delphi XE8 -


i able find 2 bcrypt libraries can compiled windows struggling compile them android in delphi xe8.

the first 1 https://github.com/chinshou/bcrypt-for-delphi doesn't require modifications compiled windows.

for second 1 https://github.com/ponypc/bcrypt-for-delphi-lazarus-fpc had make minor adjustments in checkpassword function same result since freepascal specific:

function checkpassword(const str: string; const hash: ansistring): boolean; var   regexobj: tregex;   match   : tmatch;   salt    : string; begin   regexobj := tregex.create('^\$2a\$10\$([\./0-9a-za-z]{22})',[roignorecase]);   match := regexobj.match(hash);   if match.success   begin     salt := copy(match.value,8,22);     result := hashpassword(str, salt) = hash;   end   else   begin     result := false;   end; end; 

after changing platform win android first 1 shows lot of errors since depends on comobj, windows , activex. second 1 after replacing regexpr regularexpressions , types shows conflicts results changes in string variable. code uses ansistring, ansichar cannot replace string , char since affects hashing function.

what missing? other modifications should replace obsolete ansistring , ansichar declarations, allowing code compiled android?

the string declaration problem second library caused move command in hashpassword function

move(password[1], key[0], length(password)); 

since size of password variable changed after replacing declaration ansistring string. replacing simple loop , ord function fixes problem although there more elegant way of doing it.

function hashpassword(const str: string; const salt: string): string; var   password: string ;   key, saltbytes, hash: tbytes;   i: integer; begin   password := ansitoutf8(str);    setlength(key, length(password) + 1);   := 0 length(password)-1     key[i]:=ord(password[i+1]);    key[high(key)] := 0;   saltbytes := bsdbase64decode(salt);   hash := cryptraw(key, saltbytes);   result := formatpasswordhashforbsd(saltbytes, hash); end; 

to summarize, conversion of second library android compatible code requires following changes:

  • modifying regular expression code in checkpassword function according code posted in question

  • altering uses section replacing "regexpr" "regularexpressions, types"

  • replacing declarations ansistring string , ansichar char

  • modifying hashpassword function shown above


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -