Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
0daf67d8
Commit
0daf67d8
authored
Jun 27, 2014
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extra namespace at docs removed
parent
47f8eafb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
security-passwords.md
docs/guide/security-passwords.md
+6
-6
No files found.
docs/guide/security-passwords.md
View file @
0daf67d8
...
...
@@ -17,7 +17,7 @@ When a user provides a password for the first time (e.g., upon registration), th
```php
$hash =
\yii\helpers\
Yii::$app->getSecurity()->generatePasswordHash($password);
$hash = Yii::$app->getSecurity()->generatePasswordHash($password);
```
The hash can then be associated with the corresponding model attribute, so it can be stored in the database for later use.
...
...
@@ -42,7 +42,7 @@ Yii security helper makes generating pseudorandom data simple:
```php
$key =
\yii\helpers\
Yii::$app->getSecurity()->generateRandomKey();
$key = Yii::$app->getSecurity()->generateRandomKey();
```
Note that you need to have the
`openssl`
extension installed in order to generate cryptographically secure random data.
...
...
@@ -56,7 +56,7 @@ For example, we need to store some information in our database but we need to ma
```php
// $data and $secretKey are obtained from the form
$encryptedData =
\yii\helpers\
Yii::$app->getSecurity()->encrypt($data, $secretKey);
$encryptedData = Yii::$app->getSecurity()->encrypt($data, $secretKey);
// store $encryptedData to database
```
...
...
@@ -64,7 +64,7 @@ Subsequently when user wants to read the data:
```
php
// $secretKey is obtained from user input, $encryptedData is from the database
$data
=
\yii\helpers\
Yii
::
$app
->
getSecurity
()
->
decrypt
(
$encryptedData
,
$secretKey
);
$data
=
Yii
::
$app
->
getSecurity
()
->
decrypt
(
$encryptedData
,
$secretKey
);
```
Confirming data integrity
...
...
@@ -77,14 +77,14 @@ Prefix the data with a hash generated from the secret key and data
```php
// $secretKey our application or user secret, $genuineData obtained from a reliable source
$data =
\yii\helpers\
Yii::$app->getSecurity()->hashData($genuineData, $secretKey);
$data = Yii::$app->getSecurity()->hashData($genuineData, $secretKey);
```
Checks if the data integrity has been compromised
```
php
// $secretKey our application or user secret, $data obtained from an unreliable source
$data
=
\yii\helpers\
Yii
::
$app
->
getSecurity
()
->
validateData
(
$data
,
$secretKey
);
$data
=
Yii
::
$app
->
getSecurity
()
->
validateData
(
$data
,
$secretKey
);
```
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment