将数据库中的文本密码转换为散列密码? [英] Convert text passwords in database to hashed passwords?

查看:62
本文介绍了将数据库中的文本密码转换为散列密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,我有 600 多个用户.密码以前存储为纯文本(我知道是手头上的一记耳光).无论如何,我已经更改了我的代码来存储 STA1 散列密码,但我需要转换我数据库中的现有密码,这样每个用户就不需要进入并修改他们的帐户.

In my database I have over 600 users. The passwords were previously stored as plain text (slap on hand, I know). Anyways, I have changed my code to store STA1 hashed passwords, but I need to convert the existing passwords in my database so each user doesn't need to go in and modify their account.

有什么帮助吗?

推荐答案

首先,使用 mysqldump 备份您的数据库.例如

First, backup your database with mysqldump. For example

bash#> mysqldump -u username -p nameoftable >file_to_write_to.sql

另外,请确保您的密码字段长度为 40 个字符.如果没有,请执行此 SQL 命令:

Also, make sure that your password field is 40 characters long. If not, execute this SQL command:

alter table nameoftable modify column password varchar(40);

然后更改密码:

update nameoftable set password=sha1(password) where 1;

这篇关于将数据库中的文本密码转换为散列密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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