46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
||
|
||
namespace App;
|
||
|
||
// 共通処理関数クラス
|
||
class CommonFunction
|
||
{
|
||
// 7DSRチェックデジット計算
|
||
public static function calc7dsr($number) {
|
||
$sum = 0;
|
||
$weights = [2, 3, 4, 5, 6, 7];
|
||
$digits = str_split(strrev($number));
|
||
foreach ($digits as $i => $digit) {
|
||
$sum += $digit * $weights[$i % count($weights)];
|
||
}
|
||
$checkDigit = (10 - ($sum % 10)) % 10;
|
||
return $checkDigit;
|
||
}
|
||
|
||
// 初期パスワード作成
|
||
public static function createPassword() {
|
||
// 使用可能文字 (使用不可:1,l,L,i,I,z,Z,2,o,O,0)
|
||
$chars = 'ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz3456789';
|
||
$password = '';
|
||
$length = 8;
|
||
$max = strlen($chars) - 1;
|
||
for ($i = 0; $i < $length; $i++) {
|
||
$password .= $chars[random_int(0, $max)];
|
||
}
|
||
return $password;
|
||
}
|
||
|
||
// パスワードハッシュ化
|
||
public static function hashPassword($user_seq, $password) {
|
||
$hash = hash('sha256', $password) . $user_seq . 'SOMSALT';
|
||
for ($i = 0; $i < 25; $i++) {
|
||
$hash = hash('sha256', $hash);
|
||
}
|
||
return $hash;
|
||
}
|
||
|
||
// パスワード照合
|
||
public static function verifyPassword($user_seq, $inputPassword, $hashedPassword) {
|
||
return self::hashPassword($user_seq, $inputPassword) === $hashedPassword;
|
||
}
|
||
} |