so-manager-dev.com/app/CommonFunction.php
Yu Watanabe 7d950c5cd8
All checks were successful
Deploy preview (main_watanabe) / deploy (push) Successful in 12s
9月1週分
2025-09-05 13:11:00 +09:00

41 lines
1.2 KiB
PHP
Raw 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 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 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 function hashPassword($user_seq, $password) {
$hash = hash('sha256', $password) . $user_seq . 'SOMSALT';
for ($i = 0; $i < 25; $i++) {
$hash = hash('sha256', $hash);
}
return $hash;
}
}