如何在Java中计算与Laravel兼容的Bcrypt密码 [英] How to calculate in java a Bcrypt password compatible with Laravel

查看:176
本文介绍了如何在Java中计算与Laravel兼容的Bcrypt密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内置在laravel中的系统,并且创建了一个API.问题出在身份验证中.

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

我有一个Android应用程序,并希望通过以下方式与laravel系统进行身份验证:

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

用户在Android应用中输入其密码和用户名,密码和用户名通过网络发送到laravel(密码将使用bcrypt进行哈希处理).在服务器端,laravel用接收到的用户名获取用户,并将接收到的密码与数据库中存储的密码进行比较.

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使用bcrypt来哈希用户的密码.如果我了解bcrypt算法,它使用了一些舍入运算法和加盐运算法则,因此研究laravel的代码后,我发现默认情况下它使用round = 8运算法则,但我不知道它使用了什么运算法则.我尝试使用Web bcrypt生成器输入确定的密码,但该密码与laravel计算的哈希值不匹配(并存储在数据库中).

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).

有什么建议吗?

谢谢

推荐答案

使用Bcrypt.checkpw("plain_password", "encrypted_password")对我有用.我一开始将 bcrypt 加密的哈希替换为 $ 2a $ .

It worked for me using Bcrypt.checkpw("plain_password", "encrypted_password"). I replaced the bcrypt encrypted hash with $2a$ at the beginning.

这篇关于如何在Java中计算与Laravel兼容的Bcrypt密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆