2012-08-23 5 views
1

가능한 중복 :
Secure hash and salt for PHP passwordsPHP를 사용하여 비밀번호를 해시하는 방법은 무엇입니까?

내가 haval160,4 해싱 알고리즘을 사용하여 소금으로 암호를 해시 함수를 만들어보십시오. 하지만 나는 그것이 안전하다는 것을 이해하지 못합니다. 아래 코드를 제공합니다 :

보안 시스템을 어떻게 개선 할 수 있는지 알려주십시오.

<?php  
defined("SALT")? NULL : define("SALT", "abcdefthijklmnopqursuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ*/\|[]{}()[email protected]#$%^&*_+:.,;1234567890"); 

function createSalt(){ 
     static $random_string; 
     for($i=0;$i<64;$i++){ 
      $random_string .= substr(str_shuffle(SALT), 0,25); 
     } 
    return $random_string; 
} 

global $salts;// I want to store the salt value into my database with password 
$salt = createSalt(); 
$salts = $salt;//I keep this cause I will check the matching password without database 

function createPassword($input_data,$salt){ 
    static $hash; 
    $cryc = crypt($input_data,$salt); 

     $hash = hash("haval160,4",$cryc); 

    return $hash; 
} 

$password = createPassword("123456",$salt); 
$stored_password = $password ; // I stored value into a variable cause I want to test without database 
//echo $password.'<hr>'; 

echo "Your Password: ".$password; 
echo "<br/> Your SALT VALUE: ".$salt.'<hr>'; 

function checkPassword($uid,$password,$salts,$stored_password){//this is just a test function... actual function don't require $salts and $stored_password 
    $db_uid = 1 ; 
    if($uid === $db_uid){ 

     $db_salt = $salts; 

     $db_password = createPassword($password,$db_salt); 
     if($db_password == $stored_password){ 
      echo "Password Match"; 
     }else{ 
      echo"password don't match"; 
     } 

    } 

} 

checkPassword(1,"123456",$salts,$stored_password); 

?> 
+0

http://stackoverflow.com/questions/9420722/improve-password-hashing-with-a-random-salt – Tchoupi

답변

2

사용자 고유의 암호화 알고리즘을 설계하면 안됩니다.

사용이 bcrypt 구현 : http://www.openwall.com/phpass/

require '../PasswordHash.php'; 
$hasher = new PasswordHash($hash_cost_log2=2, $hash_portable=false); // increase the first parameter if you need it to be slower (more secure) 

// Create hash 
$hash = $hasher->HashPassword($pass); 

// Check password 
$hasher->CheckPassword($pass, $hash); 

이것은 당신이, '보다 안전한'뭔가를 찾고 귀찮게하지 않습니다 얻을 수있는만큼 안전과에 염 또는 다른 것을 추가하려고하지 않습니다 그것.

관련 문제