so-manager-dev.com/app/CommonFunction.php
2025-09-12 11:11:36 +09:00

46 lines
1.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
}
}