DB中的哈希密码和哈希:: check的普通密码不相等

时间:2017-12-07 15:29:19

标签: php laravel hash

我在CRM中创建了自己的帐户。

最有趣的是密码,我已经按照这样的方式处理了它:

public static void main(String[] args)
{
    Scanner scan = new Scanner(System.in);
    int small = 0;
    int medium = 0;
    int large = 0;
    int size = 0;
    int[] intArray = {size}; 


    System.out.printf("Please enter the number of weights to enter: ");
    size = scan.nextInt();



    for (double i = 0; i < intArray.length; i++){
        if (i < size)
            System.out.print("Please Enter weight1: ");
            double weights = scan.nextInt();




    System.out.println("\nPackage Weights");
        System.out.print(weights);



        if (weights <= 5)
            small = 1 + small;
        if (weights <= 10 && weights >= 6)
            medium = 1 + medium;
        if (weights >= 11)
            large = 1 + large;

            System.out.println("\n\nSmall: " + small);
            System.out.println("Medium: " +  medium);
            System.out.println("Large:" + large);

    }
}

然后我发送带有此密码的电子邮件。

现在,当我想使用某个号码和密码登录时,我已经在我的网站上创建了登录页面。

$password = $faker->password();
$businessAccount->password = bcrypt($password);

对不起那个var_dumps,我已经把它插入到这里看看当我点击&#34;登录&#34;

时会发生什么

通过bcrypt对密码进行了哈希处理以及我的理解, Auth :: attempt 使用哈希检查普通密码。

好的,让我们走得更远。首先 var_dump 说我存储在DB中的密码,它们是相同的。

第二个 var_dump 说我&#34; bool(false)&#34;最后说我不,我认为认证失败了。

但是当我在表单中输入哈希密码时,一切都很好,我看到&#34; Hello &#34;但这是错的。

当然,我已经创建了警卫和提供者:

public function login(BusinessLoginRequest $request)
    {
        $orgNumber = $request->input('orgNumber');
        $password = $request->input('password');
        var_dump( $pass = BusinessAccounts::find('123456789')->password);
        var_dump(Hash::check($password, $pass));
        if(Auth::guard('business')->attempt(['orgNumber' => $orgNumber, 'password' => $password ])) {
                return 'Hello';
        }
        return 'no';

    }

并改变了我的模型:

'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
        'business' => [
            'driver' => 'session',
            'provider' => 'business'
        ]
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\Eloquent\Account::class,
        ],
        'business' => [
            'driver' => 'eloquent',
            'model'  => App\Models\Eloquent\BusinessAccounts::class
        ]
    ],

问题是:我做错了什么?如何检查未填写的密码?我不想从我的数据库中输入哈希密码。

1 个答案:

答案 0 :(得分:1)

尝试以这种方式哈希:

use Illuminate\Support\Facades\Hash;

然后:

'password' => Hash::make($request->newPassword)