用于加密密码的Salt Command无效

时间:2013-05-08 21:48:21

标签: php mysql password-hash

对于我们的项目,我们尝试使用salt命令加密密码,但它似乎不起作用。这是我们到目前为止所做的:

<html>
<?php
$con=msqli_connect('XXXX', '<username>', '<password>', 'XXXXXXX');
// Create connection
// Check connection
if (mysqli_connect_erno($con));
{
    echo "Failed to connect to Mysql: " . msqli_connect_error();
}
?>  

<?php
$Password = $_POST['password'];

$salt = //


$password = sha1(userPasswordinput . salt);
?>
<head>

<title>Password Ecryption</title>
</head>

<body>


</body>
</html>

与mysql的连接正常,但显然有些不对劲。密码变量是从另一个代码页发布的,该部分也正常工作。

1 个答案:

答案 0 :(得分:1)

您的代码中有一些错误会阻止salt和发布的密码正常工作。请尝试以下代码:

<?php
// lower case variable names for non-objects (developer preference)
$password_input = $_POST['password'];

// you had a syntax error here (missing variable value and ending semi-colon)
$salt = 'SomePasswordSaltString';

// you had another syntax error here (incorrect variable reference and missing $)
$password = sha1($password_input . $salt);
?>