Android Question BCrypt usage help [Solved]

Revisable5987

Member
Licensed User
Hi
Currently using the BCrypt library by donmanfred but having a little trouble with 'checkpw', possibly due to me not quite understanding the correct syntax for this lib

This is what I am using in my code:
B4X:
Private crypt As BCrypt
crypt.Initialize("")
If crypt.checkpw(string.Text, hash.Text)= True Then
'do something
    Else
    'do something else
End If
This works fine if the passwords match, however if the password is typed incorrectly my app crashes with log:
B4X:
Error occurred on line: 131 (CreatePassword)
java.lang.IllegalArgumentException: Invalid salt version
    at org.mindrot.jbcrypt.BCrypt.hashpw(BCrypt.java:659)
    at org.mindrot.jbcrypt.BCrypt.checkpw(BCrypt.java:764)
    at de.donmanfred.BCryptwrapper.checkpw(BCryptwrapper.java:58)
    at b4a.example.createpassword._checkpassword(createpassword.java:752)
    at b4a.example.createpassword$ResumableSub_CheckCredentials.resume(createpassword.java:667)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at anywheresoftware.b4a.shell.Shell.runGoodChain(Shell.java:475)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:293)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 

Peter Simpson

Expert
Licensed User
Longtime User
Hi
Currently using the BCrypt library by donmanfred but having a little trouble with 'checkpw', possibly due to me not quite understanding the correct syntax for this lib

Here you go...
Logger connected to: Google Pixel 2 XL
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
$2a$10$JNEKreseX/6PjAgL3/9bCOYC/WHI2YD25Q30jC2rGBk6wldMBBhFW
$2a$14$7WDToH3/gAy9DqdLUxfn/ebJ2PuqD003XPA5y02uBV4tKREggG5oO
true
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
B4X:
    Private BCrypt As BCrypt
    Private MyName As String = "Peter Simpson"

    Log(BCrypt.HashPW(MyName))
    Log(BCrypt.HashPW2(MyName, 14))
    Log(BCrypt.CheckPW(MyName, "$2a$14$BPHO.gjywGwTOgDt/DbZUelO.6YCjG.3nW10QvCRcBFv4eUHhqIBa"))


Enjoy...
 
Upvote 0

Revisable5987

Member
Licensed User
Thanks but problem solved!

It was my error. The database had some entries with unhashed test passwords.
The 'invalid salt version' error is thrown when using 'checkpw' on two text strings.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…