我确定这会平庸,但我无法弄清楚!
我有一个用户表:
CREATE TABLE tbl_users (
usr_id INT NOT NULL AUTO_INCREMENT ,
usr_name VARCHAR( 64 ) NOT NULL DEFAULT '' ,
usr_surname VARCHAR( 64 ) NOT NULL DEFAULT '' ,
usr_pwd BLOB NOT NULL ,
usr_level INT( 1 ) NOT NULL DEFAULT 0,
PRIMARY KEY ( usr_id )
) ENGINE = InnoDB;
有一条记录:
INSERT INTO tbl_users ( usr_id, usr_name, usr_pwd, usr_level )
VALUES (NULL, 'SU', AES_ENCRYPT('SU', SHA2('MyPwd', 512)), 2);
现在,如果我运行此查询(在phpMyAdmin中),我会得到我的记录:
SELECT usr_id, usr_name, usr_surname, usr_level,
AES_DECRYPT(usr_pwd, SHA2('MyPwd', 512)) as usr_pwd
FROM tbl_users
WHERE usr_name='SU';
但如果我添加密码检查,我会得到一个空的结果集:
SELECT usr_id, usr_name, usr_surname, usr_level,
AES_DECRYPT(usr_pwd, SHA2('MyPwd', 512)) as usr_pwd
FROM tbl_users
WHERE usr_name='SU' and usr_pwd='SU';
哪里错了?