Mysql 的加密方式( ENCODE , DECODE, md5, encrypt, password)

最後更新: 2018-01-24

目錄

  • ENCODE & DECODE
  • MD5
  • ENCRYPT
  • PASSWORD

 


ENCODE & DECODE

 

mysql> INSERT INTO users (username, password) VALUES ('datahunter', ENCODE('hereismypw', 'encodekey'));

mysql> SELECT DECODE(?????????, 'encodekey') FROM users WHERE username='datahunter';

 


MD5

 

mysql> INSERT INTO users (username, password) VALUES ('datahunter', MD5('hereismypw'));

mysql> SELECT COUNT(*) FROM users WHERE username='datahunter' AND password=MD5('hereismypw');

md5 好易受 Dictonary Attacks

 


ENCRYPT

 

It using the Unix crypt() system call and returns a string.

The salt argument must be a string with at least two characters or the result will be NULL.

If no salt argument is given, a random value is used.

Usage

ENCRYPT(string, salt)

mysql> INSERT INTO users (username, password) VALUES ('datahunter', ENCRYPT('hereismypw', 'salt'));

 


PASSWORD

 

SELECT PASSWORD('badpwd');

 


 

Creative Commons license icon Creative Commons license icon