密码允许使用哪些字符?

密码允许使用哪些字符?

我询问的是用户密码支持的字符类型(passwd确切的命令)

是否允许使用空格?空字符 (\0)?ASCII 子集或更多?

如果允许有空格,我是否需要将其转义?

答案1

根据测试:

  • \0被视为标记密码的结束。
  • 允许使用空格。虽然下面的输出中没有显示,但通过使用CtrlV,我能够在密码中使用 和其他键EnterEsc

$ pwgen 10 1
Pohhei8sai 
$ passwd 
Changing password for muru.
(current) UNIX password: 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
$ printf 'Pohhei8sai\n\0\b\n\0\b' | passwd
Changing password for muru.
(current) UNIX password: Enter new UNIX password: Retype new UNIX password: No password supplied
Enter new UNIX password: Retype new UNIX password: passwd: Authentication token manipulation error
passwd: password unchanged
$ pwgen 10 1
Uuxohv9moo 
$ printf 'Pohhei8sai\nUuxohv\09moo\nUuxohv\09moo\n' | passwd
Changing password for muru.
(current) UNIX password: Enter new UNIX password: Retype new UNIX password: Bad: new password is too simple
Enter new UNIX password: Retype new UNIX password: passwd: Authentication token manipulation error
passwd: password unchanged
$ printf 'Pohhei8sai\nUuxohv9moo\nUuxohv9moo\n' | passwd
Changing password for muru.
(current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
$ printf 'Uuxohv9moo\ntesting 1\ntesting 1' | passwd
Changing password for muru.
(current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully

从我读到的来源,该passwd命令使用(已过时)getpass函数,其行为与 非常相似read -s(并用 标记密码字符串的结尾\0)。除了检查重用性和复杂性之外,它不限制可用的字符。\0不能使用,因为它被视为 C 字符串中的正常字符串结尾标记,但几乎任何其他东西都可以使用,例如铃声:

$ printf 'testing 1\nUuxohv\a9moo\nUuxohv\a9moo\n' | passwd
Changing password for muru.
(current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully

相关内容