미디어위키 패스워드 맞는지 확인하는 함수

1 개요[ | ]

미디어위키 패스워드 맞는지 확인하는 함수
  • API도 있겠지만 문서 참고하여 간단히 만들어봄
function match_mediawiki_password($plain, $user_name) {
    $user_password = query_one("SELECT user_password
        FROM user
        WHERE user_name=?", $user_name);
    if( $user_password === false ) return "NO_USER_NAME";
    $arr = explode( ':', $password_column );
    if( count($arr) != 7 ) return "NOT_PBKDF2";
    if( $arr[1] != 'pbkdf2' ) return "NOT_PBKDF2";

    $algo = $arr[2];
    $rounds = $arr[3];
    $length = $arr[4];
    $salt = base64_decode($arr[5]);
    $hash = base64_decode($arr[6]);
    $hashed = hash_pbkdf2( $algo, $plain, $salt, $rounds, $length, true );
    if( $hash != $hashed ) return "WRONG_PASSWORD";
    return "OK";
}

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}