久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 Laravel 中對密碼使用 MD5 哈希?

How can I use MD5 hashing for passwords in Laravel?(如何在 Laravel 中對密碼使用 MD5 哈希?)
本文介紹了如何在 Laravel 中對密碼使用 MD5 哈希?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在將舊版應(yīng)用移植到 Laravel.舊的應(yīng)用程序使用 MD5 來散列密碼而不加鹽,所以我需要在 Laravel 中復(fù)制它.作為記錄,我們正在使用 salt 將密碼更改為 bcrypt,但這不是一個(gè)簡單的過程,需要用戶登錄才能這樣做 - 同時(shí)我只需要使用舊哈希登錄即可.

I'm porting over a legacy app into Laravel. The old app used MD5 to hash the passwords without a salt, so I need to replicate that within Laravel. For the record, we are changing the passwords to bcrypt with a salt, but it's not a simple process and requires a user login to do so - for the meantime I just need to get logins working with the legacy hashes.

我已按照本指南將 Auth::hash 轉(zhuǎn)換為 MD5:如何在 Laravel 4 中使用 SHA1 加密而不是 BCrypt?

I have followed this guide to convert Auth::hash to MD5: How to use SHA1 encryption instead of BCrypt in Laravel 4?

當(dāng)我在注冊帳戶時(shí)以純文本格式打印密碼和在我的 make 方法中生成的哈希值時(shí):

When I print out the password in plain text and the generated hash in my make method when registering an account:

public function make($value, array $options = array()) {
    echo $value.'<br>'.hash('md5', $value);
    exit;
    return hash('md5', $value);
}

我得到以下信息:

123456
e10adc3949ba59abbe56e057f20f883e

太好了,這正是我需要的.但是,當(dāng)它被保存到數(shù)據(jù)庫時(shí),我得到了一個(gè)完全不同的哈希值.我的猜測是 Laravel 正在其他地方添加密碼,但我找不到在哪里以及如何覆蓋它.

Great, that's what I need. However, when that is saved to the database I get a different hash entirely. My guess is that Laravel is salting the password elsewhere, but I can't find where and how to override this.

我在 app/libraries 中的 MD5Hasher.php 文件:

My MD5Hasher.php file inside app/libraries:

<?php
class MD5Hasher implements IlluminateContractsHashingHasher {

    /**
     * Hash the given value.
     *
     * @param  string  $value
     * @return array   $options
     * @return string
     */
    public function make($value, array $options = array()) {
        return hash('md5', $value);
    }

    /**
     * Check the given plain value against a hash.
     *
     * @param  string  $value
     * @param  string  $hashedValue
     * @param  array   $options
     * @return bool
     */
    public function check($value, $hashedValue, array $options = array()) {
        return $this->make($value) === $hashedValue;
    }

    /**
     * Check if the given hash has been hashed using the given options.
     *
     * @param  string  $hashedValue
     * @param  array   $options
     * @return bool
     */
    public function needsRehash($hashedValue, array $options = array()) {
        return false;
    }

}

我的MD5HashServiceProvider.php:

<?php
class MD5HashServiceProvider extends IlluminateSupportServiceProvider {

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register() {
        $this->app['hash'] = $this->app->share(function () {
            return new MD5Hasher();
        });

    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides() {
        return array('hash');
    }

}

我的 AuthController.php 如下所示:

<?php

namespace AppHttpControllersAuth;

use Hash;
use AppUser;
use Validator;
use Mail;
use AppHttpControllersController;
use IlluminateFoundationAuthThrottlesLogins;
use IlluminateFoundationAuthAuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    //protected $redirectTo = '/account';

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return IlluminateContractsValidationValidator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        $this->redirectTo = '/register/step-1';

        $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);

        // email the user
        Mail::send('emails.register', ['user' => $user], function($message) use ($user)
        {
            $message->to($user->email, $user->name)->subject('Edexus - Welcome');
        });

        // email the admin
        Mail::send('emails.register-admin', ['user' => $user], function($message) use ($user)
        {
            $message->to('admins@***.com', 'Edexus')->subject('Edexus - New user sign up');
        });

        return $user;
    }
}

推薦答案

檢查用戶模型中的密碼修改器.在控制器中對密碼進(jìn)行散列后,它再次對密碼進(jìn)行散列.

Check out the password mutator in your User Model. It's hashing the password another time after hashing it in the controller.

我的建議是在您的創(chuàng)建() 和更新() 模型事件中散列一次密碼,然后將其從增變器和控制器中刪除.

My recommendation is hash the password once in your creating() and updating() model events, and remove it from the mutator and controller.

這篇關(guān)于如何在 Laravel 中對密碼使用 MD5 哈希?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Magento products by categories(按類別劃分的 Magento 產(chǎn)品)
Resource interpreted as image but transferred with MIME type text/html - Magento(資源被解釋為圖像但使用 MIME 類型 text/html 傳輸 - Magento)
Is there an event for customer account registration in Magento?(Magento 中是否有客戶帳戶注冊事件?)
Magento addFieldToFilter: Two fields, match as OR, not AND(Magento addFieldToFilter:兩個(gè)字段,匹配為 OR,而不是 AND)
quot;Error 404 Not Foundquot; in Magento Admin Login Page(“未找到錯(cuò)誤 404在 Magento 管理員登錄頁面)
Get Order Increment Id in Magento(在 Magento 中獲取訂單增量 ID)
主站蜘蛛池模板: 91视频精品 | 影音先锋在线观看视频 | 国产在线欧美 | 操久| 亚洲视频中文字幕 | 日韩激情一区二区 | 色婷婷成人| 亚洲精品xxx| av网址在线 | 天堂中文字幕免费一区 | 亚洲在线视频观看 | 亚洲性猛交 | 中国特级毛片 | 久久av片 | 国产精品一区二区免费 | 精品视频网站 | 国产在线不卡视频 | 九九视频在线免费观看 | av福利在线观看 | 久久精品久久久 | 国产精品美女在线观看 | 欧美日韩中文字幕在线观看 | 谁有毛片网站 | 三级黄色录像片 | 日韩三级精品 | 香蕉视频一直看一直爽 | 国产激情视频在线 | 美日韩一区 | 日本精品视频 | 欧美日韩综合在线 | 簧片在线免费观看 | 亚洲视频在线免费观看 | 久久久久国产精品夜夜夜夜夜 | 国产农村妇女精品一二区 | 在线播放av网站 | 久久草av| 黄色片免费观看 | av片免费观看| 黄色三级小说 | 一区二区在线视频 | 97视频在线观看免费 |