Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

php - How to calculate in java a Bcrypt password compatible with Laravel

I have a system built in laravel and I have created an API. The problem is in Authentication.

I have an Android app and want to authenticate with the laravel system by the following way:

user type its password and username in Android app, password and username are send over network to laravel (the password will hashing with bcrypt). In server side, laravel get the user with the username received and compare the password received with the password stored in data base.

Laravel use bcrypt in order to hash user's passwords. If I understand the bcrypt algorithm it use a number of round and a salt, so investigate laravel's code I found that it use round = 8 by default but I don't know what salt it use. I tried a web bcrypt generator for a determinate password and it doesn't match with the hash calculate by laravel (and stored in data base).

Any suggestion?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I need made a workaround here to work, because when I generate with PHP, hash starts with $2y$ and java starts with $2a$.

To solve this, I create a regex in java before password match to replace $2y$ to $2a$ and works for me.

In PHP I used the native function:

$hash = password_hash($pass, PASSWORD_DEFAULT);

and in java I used jbcrypt lib.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...