如何创建一个laravel散列密码 [英] How to create a laravel hashed password

查看:150
本文介绍了如何创建一个laravel散列密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Laravel创建一个哈希密码。现在有人告诉我使用Laravel哈希帮助器,但我似乎无法找到它,或者我看错了方向。

如何创建laravel哈希密码?并在哪里?

编辑:
我知道代码是什么,但我不知道在哪里以及如何使用它,所以它让我回到散列的密码。如果我得到了散列密码,那么我可以手动将它插入到数据库中。

解决方案使用Bcrypt在<$ c $中散列密码c> Laravel :

  $ password = Hash :: make('yourpassword'); 

这将创建一个哈希密码。例如,如果用户使用 POST 方法使用表单向控制器提交密码,那么您可以使用散列函数来使用它在您的控制器或模型中像这样:

  $ password = Input :: get('passwordformfield'); //密码是表单域
$ hashed = Hash :: make($ password);

这里, $ hashed 将包含哈希密码。基本上,你会在创建/注册一个新用户时做到这一点,例如,如果用户提交的细节如 name 电子邮件,用户名密码等等,然后再将数据插入数据库,在验证数据之后,您将哈希密码。有关更多信息,请阅读文档



更新:

  $ password ='JohnDoe'; 
$ hashedPassword = Hash :: make($ password);
echo $ hashedPassword; // $ 2y $ 10 $ jSAr / RwmjhwioDlJErOk9OQEO7huLz9O6Iuf / udyGbHPiTNuB3Iuy

因此,您将插入 $ hashedPassword 到数据库中。希望,现在已经很清楚了,如果您仍然感到困惑,那么我建议您阅读一些教程,在 laracasts.com 上观看一些屏幕轮播,然后 tutsplus.com ,并阅读 Laravel 这是一个免费的电子书,您可以下载它。


$ b

由于 OP 想要使用Laravel Hash 来手动加密密码,所以没有任何类或形式,所以这是一种替代方法在命令提示符下使用 artisan tinker 的方式:


  1. 转到命令提示符/终端

  2. 导航到 Laravel 安装(您的项目的根目录)

  3. 使用 cd<目录名称> 然后按命令提示符/终端键入

  4. 然后写 php artisan tinker 并按回车

  5. 然后写 echo Hash :: ma ke('somestring');

  6. 您将在控制台上得到哈希密码,将其复制并执行任何您想要的操作。 >



更新(Laravel 5.x):



  //也可以使用bcrypt 
$ password = bcrypt('JohnDoe');





I am trying to create an hashed password for Laravel. Now someone told me to use Laravel hash helper but I can't seem to find it or I'm looking in the wrong direction.

How do I create a laravel hashed password? And where?

Edit: I know what the code is but I don't know where and how to use it so it gives me back the hashed password. If I get the hashed password then I can manually insert it into the database

解决方案

Hashing A Password Using Bcrypt in Laravel:

$password = Hash::make('yourpassword');

This will create a hashed password. You may use it in your controller or even in a model, for example, if a user submits a password using a form to your controller using POST method then you may hash it using something like this:

$password = Input::get('passwordformfield'); // password is form field
$hashed = Hash::make($password);

Here, $hashed will contain the hashed password. Basically, you'll do it when creating/registering a new user, so, for example, if a user submits details such as, name, email, username and password etc using a form, then before you insert the data into database, you'll hash the password after validating the data. For more information, read the documentation.

Update:

$password = 'JohnDoe';
$hashedPassword = Hash::make($password);
echo $hashedPassword; // $2y$10$jSAr/RwmjhwioDlJErOk9OQEO7huLz9O6Iuf/udyGbHPiTNuB3Iuy

So, you'll insert the $hashedPassword into database. Hope, it's clear now and if still you are confused then i suggest you to read some tutorials, watch some screen casts on laracasts.com and tutsplus.com and also read a book on Laravel, this is a free ebook, you may download it.

Update: Since OP wants to manually encrypt password using Laravel Hash without any class or form so this is an alternative way using artisan tinker from command prompt:

  1. Go to your command prompt/terminal
  2. Navigate to the Laravel installation (your project's root directory)
  3. Use cd <directory name> and press enter from command prompt/terminal
  4. Then write php artisan tinker and press enter
  5. Then write echo Hash::make('somestring');
  6. You'll get a hashed password on the console, copy it and then do whatever you want to do.

Update (Laravel 5.x):

// Also one can use bcrypt
$password = bcrypt('JohnDoe');


这篇关于如何创建一个laravel散列密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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