How to encrypt the database password ?
return [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=localhost;port=5432;dbname=database',
'username' => 'user',
'password' => 'abcPassword',
'charset' => 'utf8',
];
How to encrypt the database password ?
return [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=localhost;port=5432;dbname=database',
'username' => 'user',
'password' => 'abcPassword',
'charset' => 'utf8',
];
Yii2 comes with user module in advanced setup. See how it store user passwords in encrypted way.
You can use setPassword() method in User Model to get hashed passwords.
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
and call this method before saving model data.
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
return $user;
}
}
return null;
}
Also look at the Yii2 doc for passwords =>http://www.yiiframework.com/doc-2.0/guide-security-passwords.html and authentication.=> http://www.yiiframework.com/doc-2.0/guide-security-authentication.html
Try Via This way.. I didn't tasted it.. but might be helpful to you.
$database = 'mydb';
$username = 'abc';
$password = '1234';
$config['components'] = [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=192.168.*.*;dbname=' . $database,
'username' => $username,
'password' => md5($password); // Try this
'password' => Yii::$app->security->generatePasswordHash($password); // Or Else try this
'charset' => 'utf8',
]
return config;