クラスコードに定数を保持している場合に機能するこのクラスを作成していますが、ユーザーがc定数値をコメントまたはコメント解除できる外部ファイルからそれらにアクセスしたかったのです。
この方法はうまく機能しますが、ユーザーがコードを探し回ってほしくありません。
class passwordStringHandler
{
# const PWDALGO = 'md5';
# const PWDALGO = 'sha1';
# const PWDALGO = 'sha256';
# const PWDALGO = 'sha512';
const PWDALGO = 'whirlpool';
/* THIS METHOD WILL CREATE THE SALTED USER PASSWORD HASH DEPENDING ON WHATS BEEN
DEFINED */
function createUsersPassword()
{
$userspassword = 'Te$t1234';
$saltedpassword='';
if ((defined('self::PWDALGO')) && (self::PWDALGO === 'md5'))
{
$saltedpassword = md5($userspassword . $this->pwdsalt);
echo("The salted md5 generated hash is: " . $saltedpassword . "<br>");
return $saltedpassword;
}elseif ((defined('self::PWDALGO')) && (self::PWDALGO === 'sha1')){
$saltedpassword = sha1($userspassword . $this->pwdsalt);
echo("The salted sha1 generated hash is: " . $saltedpassword . "<br>");
return $saltedpassword;
}elseif ((defined('self::PWDALGO')) && (self::PWDALGO === 'sha256')){
$saltedpassword = hash('sha256', $userspassword . $this->pwdsalt);
echo("The salted sha256 generated hash is: " . $saltedpassword . "<br>");
return $saltedpassword;
}elseif ((defined('self::PWDALGO')) && (self::PWDALGO === 'sha512')){
$saltedpassword = hash('sha512', $userspassword . $this->pwdsalt);
echo("The salted sha512 generated hash is: " . $saltedpassword . "<br>");
return $saltedpassword;
}elseif ((defined('self::PWDALGO')) && (self::PWDALGO === 'whirlpool')){
$saltedpassword = hash('whirlpool', $userspassword . $this->pwdsalt);
echo("The salted whirlpool generated hash is: " . $saltedpassword . "<br>");
return $saltedpassword;
}
else
echo("No password algro is defined! Edit the [<strong>PWDALGO</strong>] options in the <strong>systemConfiguration.php</strong><br>");
return false;
}
クラスファイルにハードコードされているため、これは問題なく機能します。
これを使用して動作させたい:
require ("../configs/systemConfiguration.php");
class passwordStringHandler
{
PWDALGO が定義されている場合、 if /else ステートメントで else を取得し続けます。
またはこの方法
class passwordStringHandler
{
require ("../configs/systemConfiguration.php");
エラーが発生し続けるため、これが可能かどうかはわかりません。クラススコープ内にファイルを含めたり要求したりできるとは思いません。
将来、これが機能するようになったら、セットアップスクリプトでサーバーをチェックして、利用可能な暗号化の種類を確認し、ユーザーが優先する暗号化方法を選択できるようにリストを作成し、自動的に設定する必要がありました. 後で管理コントロール パネルから暗号化方式を変更できます。