5
5

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.

[PHP] Crack関数のインストール

Posted at

パスワード強度のチェックが必要になったため、
いろいろ探していたら、PHPにCrackというライブラリがあるのを知った。
Cracklib@php.net

引用元

最近のPHPでPECLのcrackを使う方法
Crack関数でパスワードの安全度を確かめよう

環境

$ cat /etc/redhat-release
CentOS release 6.3 (Final)

$ php -v
PHP 5.6.4 (cli) (built: Dec 17 2014 16:47:40)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies

cracklib のインストール

# yum install cracklib cracklib-devel cracklib-dict

crackのダウンロードとビルドからのインストール

$ svn export http://svn.php.net/repository/pecl/crack/trunk crack
$ cd crack
$ ./configure ; make
# make install

cracklibの辞書生成

# create-cracklib-dict /usr/share/dict/linux.words
# ls /usr/share/cracklib/
cracklib.magic  cracklib-small.hwm  cracklib-small.pwd  cracklib-small.pwi  pw_dict.hwm  pw_dict.pwd  pw_dict.pwi

crackのテストコード

cracktest.php
<?php
    // CrackLib 辞書をオープンする
    $dictionary = crack_opendict('/usr/share/cracklib/pw_dict');

    // パスワードチェックを行う
    $check = crack_check($dictionary, 'password');

    // メッセージを取得する
    $diag = crack_getlastmessage();
    echo $diag;

    // 辞書を閉じる
    crack_closedict($dictionary);

実行

$ php cracktest.php
 it is based on a dictionary word

めでたし。
JavaScript側でも探そう。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?