سهیل ملکی
2 سال پیش توسط سهیل ملکی مطرح شد
5 پاسخ

Hash password PHP

سلام دوستان خسته نباشید .
میخواستم بدونم امکانش هست توی پی اچ پی یا لاراول یه تابعی داشته باشیم که بر اساس یه کلمه خاص ، بیاد و یه الگوریتم رمزگذاری واسه خودش تعریف کنه .
به طوریکه مثلا یه کلمه هشت رقمی دست کاربر باشه و با استفاده از اون کلمه بتونه یه مقدار رو رمزگذاری کنه و داخل دیتابیس ثبت کنه اما هروقت خواست اون مقدار رو ببینه فقط با همون هشت رقم قابل ترجمه باشه .

مثلا کاربر یه کلید هشت رقمی داره و یه متن هم داره که میخواد داخل سایت باشه اما رمزگذاری شده و بعد مقدار رو با کلیدش میده به سایت و سایت هم بر اساس همون کلید یه مقدار hash تولید میکنه که فقط با کلید کاربر قابل دیدن هست و حتی ادمین سایت هم نتونه به هیچ وجه اون مقدار رو ببینه .
همچین تابعی داریم ؟؟؟
@mohammadphp
@hesammousavi
@samanzdev


ثبت پرسش جدید
احسان داوری
تخصص : برنامه نویس
@ehsndvr 2 سال پیش مطرح شد
1

با سلام
به اینکار میگن Encryption یا رمزگذاری ، هش (Hash) کردن یعنی مقداری رو جوری عوض کنید که دیگه قابل بر گشت نباشه
اما وقتی شما متنی رو رمزگذاری میکنید در صورت وجود رمز ، میتونید داده اصلی رو ببینید
مثل یک گاوصندق که اگه رمزش رو بزنید میتونید داخلش رو ببینید
حالا Encryption در PHP به این صورته :

<?php

// Store a string into the variable which
// need to be Encrypted
$simple_string = "Welcome to GeeksforGeeks\n";

// Display the original string
echo "Original String: " . $simple_string;

// Store the cipher method
$ciphering = "AES-128-CTR";

// Use OpenSSl Encryption method
$iv_length = openssl_cipher_iv_length($ciphering);
$options = 0;

// Non-NULL Initialization Vector for encryption
$encryption_iv = '1234567891011121';

// Store the encryption key
$encryption_key = "GeeksforGeeks";

// Use openssl_encrypt() function to encrypt the data
$encryption = openssl_encrypt($simple_string, $ciphering,
            $encryption_key, $options, $encryption_iv);

// Display the encrypted string
echo "Encrypted String: " . $encryption . "\n";

// Non-NULL Initialization Vector for decryption
$decryption_iv = '1234567891011121';

// Store the decryption key
$decryption_key = "GeeksforGeeks";

// Use openssl_decrypt() function to decrypt the data
$decryption=openssl_decrypt ($encryption, $ciphering, 
        $decryption_key, $options, $decryption_iv);

// Display the decrypted string
echo "Decrypted String: " . $decryption;

?>

و در لاراول به این صورت :

$newEncrypter = new \Illuminate\Encryption\Encrypter( $YourKey, Config::get( 'app.cipher' ) );
$encrypted = $newEncrypter->encrypt( $YourPassword);
$decrypted = $newEncrypter->decrypt( $YourEncryptedPassword);

موفق باشید


سبحان مولایی
تخصص : برنامه‌نویس وب: Python ::...
@websaz 2 سال پیش مطرح شد
0

سلام.
در لاراول با استفاده از کلاس Encrypter امکان پذیر هست
نمونه:

use Illuminate\Encryption\Encrypter;
$encryptor = new Encrypter(“123456” /* your hash key here */,config('app.cipher'));
// encrypt
$value =   $encryptor->encryptString(“Hello World!”);
// decrypt
$value = $encryptor->decryptString($value);

احسان داوری
تخصص : برنامه نویس
@ehsndvr 2 سال پیش مطرح شد
1

با سلام
به اینکار میگن Encryption یا رمزگذاری ، هش (Hash) کردن یعنی مقداری رو جوری عوض کنید که دیگه قابل بر گشت نباشه
اما وقتی شما متنی رو رمزگذاری میکنید در صورت وجود رمز ، میتونید داده اصلی رو ببینید
مثل یک گاوصندق که اگه رمزش رو بزنید میتونید داخلش رو ببینید
حالا Encryption در PHP به این صورته :

<?php

// Store a string into the variable which
// need to be Encrypted
$simple_string = "Welcome to GeeksforGeeks\n";

// Display the original string
echo "Original String: " . $simple_string;

// Store the cipher method
$ciphering = "AES-128-CTR";

// Use OpenSSl Encryption method
$iv_length = openssl_cipher_iv_length($ciphering);
$options = 0;

// Non-NULL Initialization Vector for encryption
$encryption_iv = '1234567891011121';

// Store the encryption key
$encryption_key = "GeeksforGeeks";

// Use openssl_encrypt() function to encrypt the data
$encryption = openssl_encrypt($simple_string, $ciphering,
            $encryption_key, $options, $encryption_iv);

// Display the encrypted string
echo "Encrypted String: " . $encryption . "\n";

// Non-NULL Initialization Vector for decryption
$decryption_iv = '1234567891011121';

// Store the decryption key
$decryption_key = "GeeksforGeeks";

// Use openssl_decrypt() function to decrypt the data
$decryption=openssl_decrypt ($encryption, $ciphering, 
        $decryption_key, $options, $decryption_iv);

// Display the decrypted string
echo "Decrypted String: " . $decryption;

?>

و در لاراول به این صورت :

$newEncrypter = new \Illuminate\Encryption\Encrypter( $YourKey, Config::get( 'app.cipher' ) );
$encrypted = $newEncrypter->encrypt( $YourPassword);
$decrypted = $newEncrypter->decrypt( $YourEncryptedPassword);

موفق باشید


سهیل ملکی
تخصص : کارآموز برنامه نویسی
@soheilsmg 2 سال پیش مطرح شد
0

خیلی ممنون عالی و کامل بود


سهیل ملکی
تخصص : کارآموز برنامه نویسی
@soheilsmg 2 سال پیش مطرح شد
0

ممنونم ازتون


احسان داوری
تخصص : برنامه نویس
@ehsndvr 2 سال پیش مطرح شد
1

@soheil.maleki
خواهش میکنم 🌹


برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام