简体   繁体   English

seafile pbkdf2哈希php

[英]seafile pbkdf2 hash php

i'm trying to generate a random password for user everytime he needs to login on my seafile server. 我试图为用户每次需要在我的seafile服务器上登录时生成一个随机密码。 seafile use: - PBKDF2 with SHA256 - 10000 iterations - 32 bytes salt seafile使用:-带有SHA256的PBKDF2-10000次迭代-32字节盐

The code i use is this: 我使用的代码是这样的:

<?php   
  $salt = random_bytes(32);
  $salt = bin2hex($salt);
  $iterations = 10000;
  echo "GENERATED SALT: " . $salt . "<br>" . "<br>";

  $hash =  hash_pbkdf2 ("sha256" , "weirdone" , $salt , $iterations);
  echo "GENERATED HASH: " . $hash . "<br>" . "<br>";

  echo "FINAL RESULT: PBKDF2SHA256$" . $iterations . "$" . $salt . "$" . $hash . "<br>" . "<br>";

?>

the problem is that even with the same salt i get different output Example: 问题是,即使使用相同的盐,我也会得到不同的输出示例:

SALT: 09d095a396852b525ce7f5408fe7d314a2632a19bfc8c495c8e79bd4e6aebfed
PASSWORD: weirdone

  seafile output:
  PBKDF2SHA256$10000$09d095a396852b525ce7f5408fe7d314a2632a19bfc8c495c8e79bd4e6aebfed$45145c60802f1fdce581a550b5e23f8027ba6ff0720c81f2efaa73025bd465ca

  my output:
  PBKDF2SHA256$10000$09d095a396852b525ce7f5408fe7d314a2632a19bfc8c495c8e79bd4e6aebfed$007c599ba2d0076e19589bb90303155efa2df8a2f6b49d845902c075bc5f5492

if the algorithm, the salt, the password and the iterations are the same why they do not match? 如果算法,盐,密码和迭代相同,为什么它们不匹配?

the goal is to generate the new password, insert it in the database and give that to the user so he can login. 目标是生成新密码,将其插入数据库并将其提供给用户,以便他可以登录。

Thanks 谢谢

您要传递十六进制编码的$ salt,需要将原始字节$ salt传递给hash_pbkdf2()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM