单行生成一个容易记忆的密码?

时间:2022-09-28 22:32:10

What's a good one-liner to generate an easily memorable password, like xkcd's correct horse battery staple or a Bitcoin seed?

什么是一个很好的单行代码生成一个容易记忆的密码,如xkcd的正确马电池主食或比特币种子?

EDIT: This is not the same as generating a random string since random strings are not at all memorable. Compare to the obligatory xkcd...

编辑:这与生成随机字符串不同,因为随机字符串根本不会令人难忘。与强制性的xkcd相比......

4 个解决方案

#1


2  

Try this,

shuf -n5 /usr/share/dict/words | sed 's/[^[:alnum:]]//g' | paste -sd_

Output:

Quayles_knockwursts_scrotums_Barrie_hauler

Explanation:

  • shuf -n5 /usr/share/dict/words Get 5 random words from dict file
  • shuf -n5 / usr / share / dict / words从dict文件中获取5个随机单词

  • sed 's/[^[:alnum:]]//g' Remove non-alphanumeric characters
  • sed's / [^ [:alnum:]] // g'删除非字母数字字符

  • paste -sd_, join the words with underscore (_)
  • 粘贴-sd_,用下划线加入单词(_)

#2


2  

You need a wordlist dictionary, since you mention bitcoin, most likely you want this one:

你需要一个wordlist字典,因为你提到比特币,很可能你想要这个:

https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt

If your native language is not English, there are wordlists for other languages available in the same repository.

如果您的母语不是英语,则可以在同一存储库中提供其他语言的单词表。

Given this english.txt file, you can do a random selection with shuf:

鉴于此english.txt文件,您可以使用shuf进行随机选择:

$ shuf -n 4 english.txt 
anchor
neck
trumpet
response

Note you'll need way more than just 4 words for a truly secure passphrase. 4 words is for an online service where the number of attempts an attacker might do is very limited. I think the bitcoin recommendation is 16 words, not sure.

请注意,您需要的不仅仅是4个单词才能获得真正安全的密码短语。 4个单词用于在线服务,其中攻击者可能进行的尝试次数非常有限。我认为比特币推荐是16个字,不确定。

Also in this example, each word may only appear once. If you wish to allow repeated words, you have to duplicate the wordlist itself:

同样在这个例子中,每个单词可能只出现一次。如果您希望允许重复的单词,则必须复制单词表本身:

$ cat english.txt english.txt | shuf -n 4

That would allow each word to appear twice. Of course you can re-create your english.txt to contain each word multiple times in the first place, then go back to the original command.

这将允许每个单词出现两次。当然,您可以重新创建您的english.txt,以便首先包含多个单词,然后返回原始命令。

If you want the output in one line, you can just add xargs echo:

如果你想要输出一行,你可以添加xargs echo:

$ shuf -n 4 english.txt | xargs echo
math easily cube daughter

On a sidenote, I don't find this style of password to be easily memorable.

在旁注中,我发现这种风格的密码不容易记忆。

Well, actually I got very lucky with math easily cube daughter since that just happens to make it easy to think of a story where your daughter can easily do math with cubes or whatever. It's something humans can relate to, as is the horse in XKCD's example.

嗯,实际上我很幸运,数学很容易立方体女儿,因为这恰好可以让你很容易想到一个故事,你的女儿可以很容易地用立方体或其他什么做数学。这是人类可以联系到的东西,就像XKCD的例子中的马一样。

But what the heck is a anchor neck trumpet response? I'm not a comic book author with creativity to spare to come up with a mnemonic for that. So it will be forgotten in no time.

但到底是一个锚颈喇叭响应呢?我不是一个有创造力的漫画书作者,为此想出一个助记符。所以它很快就会被遗忘。

Even if you can remember the words, it's hard to remember their correct order. Was it math easily cube daughter or daugher easily math cube or something else?

即使你能记住这些词,也很难记住它们的正确顺序。是数学容易立方体女儿或daugher容易数学立方体或其他什么?

And the password is supposed to be random, you're not allowed to pick and modify it.

密码应该是随机的,你不能选择和修改密码。


As for bitcoin seeds, you're not really supposed to remember them. This is just a way to be able to write it down easily. Anyone can write down 16 words on a piece of paper and read them back correctly; with random letters it's much more likely to make mistakes.

至于比特币种子,你真的不应该记住它们。这只是一种能够轻松写下来的方法。任何人都可以在一张纸上写下16个单词并正确阅读;随机字母更容易出错。

#3


1  

I have this:

我有这个:

xkcd_password () { 
    command grep "^[[:alpha:]]\{5,8\}$" "${1-/usr/share/dict/words}" | sort -R | head -4
}

#4


0  

First of all, install a dictionary of a language you're familiar with, using:

首先,使用以下方法安装您熟悉的语言字典:

sudo apt-get install <language-package>

To see all available packages:

要查看所有可用包:

apt-cache search wordlist | grep ^w

Note: all installation instructions assume you're on a debian-based OS.

注意:所有安装说明都假设您使用的是基于debian的操作系统。

After you've installed dictionary run:

安装字典后运行:

WORDS=5; grep '^[pyfgcrlaoeuidhtnsqjkxbmwvz]*$' /usr/share/dict/words | shuf -n ${WORDS} | tr '\n' '-' | sed 's/-$//'

Which will output ex:

哪个会输出ex:

blasphemous-commandos-vasts-suitability-arbor

To break it down:

要打破它:

  • WORDS=5; - choose how many words you wan in your password
  • WORDS = 5; - 选择密码中的字数

  • grep '^[pyfgcrlaoeuidhtnsqjkxbmwvz]*$' /usr/share/dict/words - choose only words containing lowercase alphabet characters (it excludes words with ' in them or funky characters like in éclair)
  • grep'^ [pyfgcrlaoeuidhtnsqjkxbmwvz] * $'/ usr / share / dict / words - 只选择包含小写字母字符的单词(不包含带有'in in或带有éclair的时髦字符的单词)

  • shuf -n ${WORDS} - chose as many WORDS as you've requested
  • shuf -n $ {WORDS} - 根据您的要求选择了尽可能多的单词

  • tr '\n' '-' - join all words using - (feel free to change it)
  • tr'\ n'' - ' - 使用 - 加入所有单词 - (随意更改)

  • sed 's/-$//' - remove trailing -
  • sed's / - $ //' - 删除尾随 -

Alternatively you can wrap it in a function:

或者,您可以将其包装在一个函数中:

#!/bin/bash

function memorable_password() {
  words="${1:-5}"
  sep="${2:--}"

  grep '^[pyfgcrlaoeuidhtnsqjkxbmwvz]*$' /usr/share/dict/words | shuf -n ${words} | tr '\n' ${sep} | sed "s/${sep}$/\n/"
}

or

#!/bin/sh

memorable_password() {
  words="$1"
  if [ -z "${words}" ]; then
    words=5
  fi

  sep="$2"
  if [ -z "${sep}" ]; then
    sep="-"
  fi

  grep '^[pyfgcrlaoeuidhtnsqjkxbmwvz]*$' /usr/share/dict/words | shuf -n ${words} | tr '\n' ${sep} | sed "s/${sep}$/\n/"
}

Both of which can be called as such:

两者都可以这样称呼:

memorable_password 7 _
memorable_password 4
memorable_password

Returning:

skipped_cavity_entertainments_gangway_seaports_spread_communique
evaporated-*es-bold-presuming
excelling-thoughtless-pardonable-promulgated-forbearing

Hope that helps ^^

希望有助于^^

#1


2  

Try this,

shuf -n5 /usr/share/dict/words | sed 's/[^[:alnum:]]//g' | paste -sd_

Output:

Quayles_knockwursts_scrotums_Barrie_hauler

Explanation:

  • shuf -n5 /usr/share/dict/words Get 5 random words from dict file
  • shuf -n5 / usr / share / dict / words从dict文件中获取5个随机单词

  • sed 's/[^[:alnum:]]//g' Remove non-alphanumeric characters
  • sed's / [^ [:alnum:]] // g'删除非字母数字字符

  • paste -sd_, join the words with underscore (_)
  • 粘贴-sd_,用下划线加入单词(_)

#2


2  

You need a wordlist dictionary, since you mention bitcoin, most likely you want this one:

你需要一个wordlist字典,因为你提到比特币,很可能你想要这个:

https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt

If your native language is not English, there are wordlists for other languages available in the same repository.

如果您的母语不是英语,则可以在同一存储库中提供其他语言的单词表。

Given this english.txt file, you can do a random selection with shuf:

鉴于此english.txt文件,您可以使用shuf进行随机选择:

$ shuf -n 4 english.txt 
anchor
neck
trumpet
response

Note you'll need way more than just 4 words for a truly secure passphrase. 4 words is for an online service where the number of attempts an attacker might do is very limited. I think the bitcoin recommendation is 16 words, not sure.

请注意,您需要的不仅仅是4个单词才能获得真正安全的密码短语。 4个单词用于在线服务,其中攻击者可能进行的尝试次数非常有限。我认为比特币推荐是16个字,不确定。

Also in this example, each word may only appear once. If you wish to allow repeated words, you have to duplicate the wordlist itself:

同样在这个例子中,每个单词可能只出现一次。如果您希望允许重复的单词,则必须复制单词表本身:

$ cat english.txt english.txt | shuf -n 4

That would allow each word to appear twice. Of course you can re-create your english.txt to contain each word multiple times in the first place, then go back to the original command.

这将允许每个单词出现两次。当然,您可以重新创建您的english.txt,以便首先包含多个单词,然后返回原始命令。

If you want the output in one line, you can just add xargs echo:

如果你想要输出一行,你可以添加xargs echo:

$ shuf -n 4 english.txt | xargs echo
math easily cube daughter

On a sidenote, I don't find this style of password to be easily memorable.

在旁注中,我发现这种风格的密码不容易记忆。

Well, actually I got very lucky with math easily cube daughter since that just happens to make it easy to think of a story where your daughter can easily do math with cubes or whatever. It's something humans can relate to, as is the horse in XKCD's example.

嗯,实际上我很幸运,数学很容易立方体女儿,因为这恰好可以让你很容易想到一个故事,你的女儿可以很容易地用立方体或其他什么做数学。这是人类可以联系到的东西,就像XKCD的例子中的马一样。

But what the heck is a anchor neck trumpet response? I'm not a comic book author with creativity to spare to come up with a mnemonic for that. So it will be forgotten in no time.

但到底是一个锚颈喇叭响应呢?我不是一个有创造力的漫画书作者,为此想出一个助记符。所以它很快就会被遗忘。

Even if you can remember the words, it's hard to remember their correct order. Was it math easily cube daughter or daugher easily math cube or something else?

即使你能记住这些词,也很难记住它们的正确顺序。是数学容易立方体女儿或daugher容易数学立方体或其他什么?

And the password is supposed to be random, you're not allowed to pick and modify it.

密码应该是随机的,你不能选择和修改密码。


As for bitcoin seeds, you're not really supposed to remember them. This is just a way to be able to write it down easily. Anyone can write down 16 words on a piece of paper and read them back correctly; with random letters it's much more likely to make mistakes.

至于比特币种子,你真的不应该记住它们。这只是一种能够轻松写下来的方法。任何人都可以在一张纸上写下16个单词并正确阅读;随机字母更容易出错。

#3


1  

I have this:

我有这个:

xkcd_password () { 
    command grep "^[[:alpha:]]\{5,8\}$" "${1-/usr/share/dict/words}" | sort -R | head -4
}

#4


0  

First of all, install a dictionary of a language you're familiar with, using:

首先,使用以下方法安装您熟悉的语言字典:

sudo apt-get install <language-package>

To see all available packages:

要查看所有可用包:

apt-cache search wordlist | grep ^w

Note: all installation instructions assume you're on a debian-based OS.

注意:所有安装说明都假设您使用的是基于debian的操作系统。

After you've installed dictionary run:

安装字典后运行:

WORDS=5; grep '^[pyfgcrlaoeuidhtnsqjkxbmwvz]*$' /usr/share/dict/words | shuf -n ${WORDS} | tr '\n' '-' | sed 's/-$//'

Which will output ex:

哪个会输出ex:

blasphemous-commandos-vasts-suitability-arbor

To break it down:

要打破它:

  • WORDS=5; - choose how many words you wan in your password
  • WORDS = 5; - 选择密码中的字数

  • grep '^[pyfgcrlaoeuidhtnsqjkxbmwvz]*$' /usr/share/dict/words - choose only words containing lowercase alphabet characters (it excludes words with ' in them or funky characters like in éclair)
  • grep'^ [pyfgcrlaoeuidhtnsqjkxbmwvz] * $'/ usr / share / dict / words - 只选择包含小写字母字符的单词(不包含带有'in in或带有éclair的时髦字符的单词)

  • shuf -n ${WORDS} - chose as many WORDS as you've requested
  • shuf -n $ {WORDS} - 根据您的要求选择了尽可能多的单词

  • tr '\n' '-' - join all words using - (feel free to change it)
  • tr'\ n'' - ' - 使用 - 加入所有单词 - (随意更改)

  • sed 's/-$//' - remove trailing -
  • sed's / - $ //' - 删除尾随 -

Alternatively you can wrap it in a function:

或者,您可以将其包装在一个函数中:

#!/bin/bash

function memorable_password() {
  words="${1:-5}"
  sep="${2:--}"

  grep '^[pyfgcrlaoeuidhtnsqjkxbmwvz]*$' /usr/share/dict/words | shuf -n ${words} | tr '\n' ${sep} | sed "s/${sep}$/\n/"
}

or

#!/bin/sh

memorable_password() {
  words="$1"
  if [ -z "${words}" ]; then
    words=5
  fi

  sep="$2"
  if [ -z "${sep}" ]; then
    sep="-"
  fi

  grep '^[pyfgcrlaoeuidhtnsqjkxbmwvz]*$' /usr/share/dict/words | shuf -n ${words} | tr '\n' ${sep} | sed "s/${sep}$/\n/"
}

Both of which can be called as such:

两者都可以这样称呼:

memorable_password 7 _
memorable_password 4
memorable_password

Returning:

skipped_cavity_entertainments_gangway_seaports_spread_communique
evaporated-*es-bold-presuming
excelling-thoughtless-pardonable-promulgated-forbearing

Hope that helps ^^

希望有助于^^