Cakephp 2.1 encrypt and decrypt a string - cakephp-2.1

I'm using Cakephp 2.1.
How can I encrypt and decrypt a string.

As per CakePHP documentation:
Encrypt your secret password with my_key
$secret = Security::cipher('my secret password', 'my_key');
Later decrypt your secret password
$nosecret = Security::cipher($secret, 'my_key');

Related

Laravel encrypt password before storing on DB and decrypt it to use on email settings

I followed this tutorial to create dynamic email settings stored on db.
https://kayike.medium.com/enable-unique-and-dynamic-smtp-mail-settings-for-each-user-laravel-48e320d381ec
The only problem is that the password is not encrypted. I would like to encrypt it before storing on db and decrypt it before using on MailServiceProvider.
I tried to use bcrypt but it can't be de-crypted. Any suggestions?
Thanks
see the docs for encryption: https://laravel.com/docs/8.x/encryption
encrypting password:
$encrypted = crypt::encryptString($password);
//store this to database
decrypting password:
$decrypted_password = crypt::decryptString($encrypted);
//use this for mailer settings
Note: don't forget to use namespace Illuminate\Support\Facades\Crypt;
in the controller
Additional Note for bcrypt:
encryption-decryption is different than hashing, bcrypt is a hashing formula which can't be decrypted (one way process).

how to encrypt password provided and compare with Database data in Oauth 2.0 to get access token?

Actually i am using basic authentication in postman and provide client id and secret to get basic authentication key.Then i have provided username,password and grant type to get access token.since my password is encrypted and stored in my DB.I have to pass encrypted password to get access token.Is there any way to encrypt my passed password to compare for authorization and get access token.

JWT is not returning token when i pass Hashed password

I am using JWT for generating tokens in Laravel 5.
When I am trying to get JWT token via user email and hashed password or bcrypted password it is returning me false. But when I am doing it without hashed password or bcrypted password, JWT is able to generate token for my application.
How can I make JWT to generate token when i am passing hashed or bcrypted passwords ?
You do not pass hashed passwords to the default Auth class of Laravel because the Auth class hash your passwords before validating them against database. JWT is leveraging the Auth controller and hence it expects non hashed passwords because it is hashing them anyway

Encrypt database field using user passord as part of the procedure in Laravel

Laravel 5.0
I want to encrypt some data in the database using not only the application key but also the users password or any other string that HE will provide.
The reason is that i want only him to be able to decrypt the data.
How would i go about it?
-Use Javascript and encrypt the password locally and then send it to the server?
or
-Send the text that user enters directly to the server?
All traffic will be upon HTTPS
// Encrypt
$key = md5(Config::get('app.key') . $userString);
Crypt::setKey($key);
$encypted = Crypt::encrypt($input);
// decrypt
$key = md5(Config::get('app.key') . $userString);
Crypt::setKey($key);
$decypted = Crypt::decrypt($encypted);

Magento password encrypt in my custom module

I am new to magento.
In my site, I want to create new profile module.
In my new module have like this fields also
current password
new password
confirm new password.
By default the password stored encrypt password like this 24d2f566950ed1af94c01d1ec5ce0f48:2e.
My Question is How to encrypt password like this in magento?
To get a password hash like Magento does it you can use the Encryption model in Core like so:
$password = 'test';
$encrypted = Mage::getSingleton('core/encryption')->getHash($password);
If you'd like to validate the encrypted value with the plain password you can do so using the same model:
Mage::getSingleton('core/encryption')->validateHash($password, $encrypted);
Replace encpt password in database "admin_user" table with all default setting:
temp password: admin123#
encpt password: 3bfea6f5ac1c57c3ce9a9165338cbc5c:CA1Byy3NifFoWVhjBxI3mD2bgAnj4qn7
sometime it does not work on Chrome:
http://www.customerparadigm.com/easy-fix-for-chrome-magento-admin-login/
Thanks

Resources