PASSWORD HASH
[PASSWORD 암호화]
// 비밀번호 암호화
$hash = password_hash($password, PASSWORD_DEFAULT);
// 비밀번호 일치하는지 비교
if (password_verify($password, $hash_password)) {
// 비밀번호 일치
}
PASSWORD
[PASSWORD SQL문 생성]
SELECT CONCAT('*', UPPER(SHA1(UNHEX(SHA1(str)))));
[PASSWORD 함수 만들기]
CREATE DEFINER=CURRENT_USER() FUNCTION password(
`str` TEXT
)
RETURNS varchar(41) CHARSET utf8
LANGUAGE SQL
NOT DETERMINISTIC
NO SQL
SQL SECURITY DEFINER
COMMENT '버전 8에서 password 함수는 삭제됨'
BEGIN
DECLARE pwd VARCHAR(41);
SELECT CONCAT('*', UPPER(SHA1(UNHEX(SHA1(str))))) INTO pwd;
RETURN pwd;
END
OLD_PASSWORD
[PHP Function old_password]
function old_password($password) {
$nr=0x50305735;
$nr2=0x12345671;
$add=7;
$charArr = preg_split("//", $password);
foreach ($charArr as $char) {
if (($char == '') || ($char == ' ') || ($char == '\t')) continue;
$charVal = ord($char);
$nr ^= ((($nr & 63) + $add) * $charVal) + ($nr << 8);
$nr2 += ($nr2 << 8) ^ $nr;
$add += $charVal;
}
return sprintf("%08x%08x", ($nr & 0x7fffffff), ($nr2 & 0x7fffffff));
}
[SQL CREATE FUNCTION OLD_PASSWORD]
DROP FUNCTION IF EXISTS OLD_PASSWORD;
DELIMITER $$
CREATE DEFINER=CURRENT_USER() FUNCTION OLD_PASSWORD (input BLOB)
RETURNS CHAR(16)
DETERMINISTIC
BEGIN
DECLARE nr BIGINT;
DECLARE nr2 BIGINT;
DECLARE ad BIGINT;
DECLARE inlen INT;
DECLARE i INT;
DECLARE b CHAR;
DECLARE tmp INT;
DECLARE output CHAR(16);
SET nr = 1345345333;
SET nr2 = 0x12345671;
SET ad = 7;
SET inlen = LENGTH(input);
SET i = 1;
IF (input = '' OR input IS NULL) THEN
RETURN input;
END IF;
WHILE i <= inlen DO
SET b = MID(input, i, 1);
IF b != ' ' AND b != '\t' THEN
SET tmp = ORD(b);
SET nr = nr ^ ((((nr & 63) + ad) * tmp) + ((nr << 8) & 0xFFFFFFFF));
SET nr2 = nr2 + (((nr2 << 8) & 0xFFFFFFFF) ^ nr);
SET ad = ad + tmp;
END IF;
SET i = i + 1;
END WHILE;
SET nr = nr & ((1 << 31) - 1);
SET nr2 = nr2 & ((1 << 31) - 1);
SET output = LOWER(CONCAT(LPAD(HEX(nr),8,'0'), LPAD(HEX(nr2),8,'0')));
RETURN output;
END$$
DELIMITER ;