dongle2627 2011-06-16 03:48
浏览 85
已采纳

使用Linux用来散列用户密码的算法来散列字符串?

What's the algorithm that Linux uses to hash users' passwords? How can I implement that algorithm in PHP?

  • 写回答

2条回答 默认 最新

  • dscizpq790832708 2011-06-16 05:45
    关注

    You might need to know some background information on Linux password storage formats - especially on shadowed password configuration before you can actually implement your own.

    On Linux distributions using glibc2, the hash function has a 'magic bit' and salt prefixed to it.

    The magic bit starts off with '$x$' and is used to determined the hash function that was used:

    • $1$ for MD5
    • $2$ for Blowfish,
    • $5$ for SHA-256 and
    • $6$ for SHA-512

    (Other unix systems like NetBSD might have different values for this).

    The magic bit then followed by 8 bits that constitutes the salt and optionally is terminated by another "$". Between this and the next "$", you will find the actual password hash.

    Almost all modern Linux systems these days do NOT store the passwords in the world-readable /etc/passwd. Instead the passwords are shadowed in /etc/shadow where only root is allowed read permission. If the shadowed password scheme in use, the /etc/passwd file shows a character such as '*', or 'x' instead of the password.

    The format of a typical password in /etc/shadow would looks like this:

    $a:$b:$c:$e:$f:$g:$h:$i
    

    Where:

    $a: username

    $b: salt and hashed password (as explained above). If this is "NP" or "!" or null then it means that the account has no password. "LK" or "*" means the account is locked and the user will be unable to log-in. "!!" means that the password has expired

    $c: Days since epoch of last password change

    $d: Days until change allowed

    $e: Days before change required

    $f: Days warning for expiration

    $g: Days before account inactive

    $h: Days since epoch when account expires

    $i: Reserved for future use.

    An example of a shadowed password file could be found at: http://configuration.logfish.net/index.php/etc/shadow

    References:

    crypt(3) - Linux man page

    Why shadow your passwd file?

    Understanding Linux Password Hashes

    Shadow password on wikipedia

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog