douwei8096 2015-10-17 17:15
浏览 71
已采纳

如何使用CakePHP哈希算法和SALT编写用于在CakePHP网站数据库中为MySQL生成加密密码的SQL语句?

I have a MySQL database and User table. I store different types of users with different roles in User table.

I am using CakePHP framework. In my core.php file, I have added SALT and HASH code for storing the encrypted password in DB. Now everything is good here so far. And CakePHP will make sure to stored encrypted password in DB.

Consider this scenario: I am trying to register the Webmaster/WebAdmin user. I will not be able to provide the Register User link for WebMaster. Only from back-end I should be able to add the WebAdmin/Webmaster user.

So I need to be able to create the Admin user and store his password using the SQL statement and utilizing the same HASH and SALT used by CakePHP to authorize/authenticate the WebAdmin user from front-end page.

I am not very familiar with how to write this type of SQL statement for MySQL DB to accomplish this task. And I am not sure if this is even achievable. How to accomplish this?

If nothing works then I will have to provide a temp View to register and then remove this view from the code. But I do not really like this option if there is a way to achieve this using SQL statement on MySQL DB.

  • 写回答

1条回答 默认 最新

  • duanqian6295 2015-10-17 18:16
    关注

    The most portable way would be to add the 'secret' function & view to your User controller as you wrote, because you don't know exactly how CakePHP processes the salt and hash. It could use any of the available hash functions.

    But adding such a function is not so bad if you check in the code if the account already exists. Even if somebody guesses the URL the account will only be added once. Of course, once the acocunt is created you should immediately login and change the password to something that is not in your code.

    An alternative would be to create the admin as a regular user first, then using PHPMyAdmin or commandline mysql change the privilege level of the account directly in the database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度