본문 바로가기

PHP/새로운문법

암호화 라이브러리(phpass 0.5)


php 내장 함수인 password_hash() 사용하면된다.

강력한 암호화이며 salt값을 자동으로 추가한다.



<?php

header("Content-Type: text/html; charset=UTF-8");

$password = "홍길동 날다";

// 비밀번호를 해시합니다.  $hashedPassword 는 60자 문자열이 됩니다.

$hashedPassword = password_hash($password, PASSWORD_DEFAULT);


echo $hashedPassword;

// 이제 $hashedPassword 내용을 안전하게 데이터베이스에 저장할 수 있습니다.

echo "<br />";

// 사용자가 입력한 것과 해시를 비교하여 올바른 비밀번호를 입력했는지 확인합니다.

var_dump("assword_verify($password, $hashedPassword)"); // false

echo "<br />";

print password_verify('my super cool password', $hashedPassword); // true

?>









아래 암호화는 php 5.3이하버전에서 사용한다.


<?php

// Include the phpass library

require_once('phpass-0.5/PasswordHash.php');


// Initialize the hasher without portable hashes (this is more secure)

$hasher = new PasswordHash(8, false);


// Hash the password.  $hashedPassword will be a 60-character string.

$hashedPassword = $hasher->HashPassword('my super cool password');

echo "hash: ".$hashedPassword."<br />";


// You can now safely store the contents of $hashedPassword in your database!


// Check if a user has provided the correct password by comparing what they typed with our hash

$v1 = $hasher->CheckPassword('the wrong password', $hashedPassword); // false


$v2 = $hasher->CheckPassword('my super cool password', $hashedPassword); // true


var_dump($v1);

var_dump($v2);


// echo "Password : $password | $hash | Password Checked : $checked";

?>










http://www.meye.net/php-best-practices/#mysql





http://blueds99.tistory.com/25

'PHP > 새로운문법' 카테고리의 다른 글

파일 삭제  (0) 2017.11.17
파일다운로드  (1) 2017.11.17
페이징에서 악의적 접근 차단하기  (0) 2017.11.14
현재 시간 입력  (0) 2017.11.14
PHP 절대경로  (0) 2017.11.14