我正在使用 RIJNDAEL 加密/解密密码和其他一些字符串,但它不起作用。
这是我的加密/解密功能:
function secreto($accion,$clave,$palabra) {
//SETEO DATA EN 0 PORSIACA
$data = 0;
//INICIALIZO EL VECTOR
$iv = md5($clave);
//SI TENGO QUE ENCRIPTAR
if($accion == 'encripta') {
$data = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $clave, $palabra, MCRYPT_MODE_CBC, $iv);
$data = base64_encode($data);
} elseif($accion == 'decripta') {
$data = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $clave, base64_decode($palabra), MCRYPT_MODE_CBC, $iv);
$data = rtrim($data, "");
}
return $data;
}
这是我用来登录用户的相关部分:
session_start();
if(isset($_SESSION['usuario']) && isset($_SESSION['domadmin']) && isset($_SESSION['superadmin'])) {
$usuario = $_SESSION['usuario'];
$tipoadmin = $_SESSION['tipoadmin'];
if(isset($_GET['p'])) { $p = $_GET['p']; } else { $p = "resumen"; }
echo TPcabecera();
echo TPmenu($p);
echo TPcentral($p);
echo TPpie();
} else {
if(isset($_POST['usuario']) && isset($_POST['password'])) {
$post_usr = mysqli_real_escape_string(sqls("mail"), $_POST['usuario']);
$post_pwd = mysqli_real_escape_string(sqls("mail"), $_POST['password']);
$data = sql("mail", "SELECT email,superadmin,domadmin,syspass FROM users WHERE email = '".$post_usr."'");
if(mysqli_num_rows($data) == 0) {
echo TPlogin();
} else {
$row = mysqli_fetch_assoc($data);
$pass = secreto('decripta',$passsalt,$row['syspass']);
if($post_pwd == $pass) {
$usuario = $row['email'];
if($row['superadmin'] == '1') { $tipoadmin = 'superadmin'; } elseif($_SESSION['domadmin'] != '0') { $tipoadmin = $_SESSION['domadmin']; } else { $tipoadmin = '0'; }
if(isset($_GET['p'])) { $p = $_GET['p']; } else { $p = "resumen"; }
echo TPcabecera();
echo TPmenu($p);
echo TPcentral($p);
echo TPpie();
} else {
echo TPlogin();
}
}
} else {
echo TPlogin();
}
}
如果我回显$pass
and $post_pwd
,它们完全相同,但if($post_pwd == $pass)
不验证...我是否以错误的方式使用加密?