crypt函数salt如何取值才能得到和shadow中的密码串一致? - C/C++ - ...

来源:百度文库 编辑:神马文学网 时间:2024/04/28 03:28:59
GNU EXTENSION
       The glibc2 version of this function has the following additional features.  If salt is a character string
       starting  with the three characters "$1$" followed by at most eight characters, and optionally terminated
       by "$", then instead of using the DES machine, the glibc crypt function uses an MD5-based algorithm,  and
       outputs  up  to  34 bytes, namely "$1$$", where "" stands for the up to 8 characters
       following "$1$" in the salt, and "" is a further 22 characters.  The characters in ""  and
       ""  are  drawn  from the set [a-zA-Z0-9./].  The entire key is significant here (instead of only
       the first 8 bytes).

       Programs using this function must be linked with -lcrypt.



[root@server tmp]# useradd prettywolf
[root@server tmp]# passwd prettywolf
Changing password for user prettywolf.
New UNIX password:             12345
BAD PASSWORD: it is too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@server tmp]# tail -1 /etc/shadow
prettywolf:$1$qY9g/6K4$KTVzAcT.TMgkASuMWh6kJ1:13826:0:99999:7:::
[root@server tmp]# cat c.c
#include
#include

int main(void) {
  char *salt = "$1$qY9g/6K4$";
  printf("%s\n", crypt("12345", salt));
  return(0);
}
[root@server tmp]# gcc -o c c.c -lcrypt
[root@server tmp]# ./c
$1$qY9g/6K4$KTVzAcT.TMgkASuMWh6kJ1