drhzc64482 2017-09-05 16:57
浏览 33

laravel auth将bcrypt应用于用户名/电子邮件

The laravel auth system uses bcrypt for saving passwords. Is it possible to do the same for the username (i.e. email)? I want to avoid that any customer email addresses are save plain text in the DB.

EDIT:

I don't need to know the user email for any other functionality. I only want the users to be able to login with their email address. I am just wondering if there is an easy way to do this with the integrated laravel auth system or if I need to write the whole auth logic myself

  • 写回答

1条回答 默认 最新

  • douhui9631 2017-09-05 17:11
    关注

    The general flow for authenticating a user against a hashed password is:

    1. User submits username and password
    2. One user entity is fetched from database based on the username
    3. Password is checked using password_verify
    4. User is authenticated (or not)

    This relies on the username being stored in plain-text, since otherwise the second step cannot be performed. If you were to hash the username as well, the process would need to become:

    1. User submits username and password
    2. Every user is fetched from the database
    3. Username and password are both checked using password_verify
    4. User is authenticated (or not)

    This is in theory a workable approach, but it is not at all scalable. Step 2 requires either fetching all users into memory, or paging through them, both of which will add significant overhead. Verifying hashed data is also (by design) an expensive operation, and if you have to perform it twice for every user in your database, every time anyone logs in, you'll quickly run into trouble.

    I think one thing you might be missing is that password_hash generates a different hash each time, even for the same input string. This is what makes the second approach unworkable, since it prevents looking up a single user.

    Additionally, as was mentioned in the comments, anything hashed using bcrypt is going to stay hashed. You might not need to actually send emails to the user, but you'll also lose the ability to display their username on the site, either in a user profile page or alongside any content/etc.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题