11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

/dev/urandomで予測困難なトークンを作成

Last updated at Posted at 2012-03-16

徳丸本より引用。PHPのrand()を使うより予測困難性が高いらしい。

<?php
function getToken() {
  $s = file_get_contents('/dev/urandom', false, NULL, 0, 24);
  return base64_encode($s);
}

おそらくrand()を使うよりは遅いので、セキュリティ用途のものを作るときだけ、など使い分けるといい。

11
11
0

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
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?