VOOZH about

URL: https://qiita.com/wai-doi/items/cec97cc38642df26b28e

⇱ 簡単にパスワードを作るRubyワンライナー #Ruby - Qiita


👁 Image
2

Go to list of users who liked

3

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@wai-doi(Yusuke Doi)in👁 Image
株式会社永和システムマネジメント

簡単にパスワードを作るRubyワンライナー

2
Last updated at Posted at 2018-03-16

就活をしていると、企業のマイページ毎にパスワードを作る必要があったので書きました。

組み込みライブラリで単純に

$ruby -e 'puts 8.times.map{[*"A".."Z", *"a".."z", *0..9].sample}.join'

パスワードはシンプルに大文字、小文字、数字で構成されます。
同じ文字が何回もあってもいいとしました。
桁数を変えたければ、8を任意の数に変えてください。

ですが、この方法でパスワードを作るのはダメです。
sampleを使ったパスワードは安全とは言えません。予測されてしまいます。
詳しくは、「Rubyのsecurerandomを使う意味」の回答を参照してください。

SecureRandomで安全に

$ruby -r securerandom -e 'puts SecureRandom.alphanumeric(8)'

安全なパスワードを作るにはsecurerandomを用いるのが良いようです。
SecureRandom.alphanumericを使えば大文字、小文字、数字の安全なパスワードが作れます。

2

Go to list of users who liked

3
0

Go to list of comments

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2

Go to list of users who liked

3