-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement password salts #7
Open
lennartvdd
wants to merge
5
commits into
mishamx:master
Choose a base branch
from
lennartvdd:feature/salted_passwords
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
703d969
Implement password salts
lennartvdd ce7c5d8
Improvement of password salts & small bugfix
lennartvdd f574da4
Add salt column in schema files.
lennartvdd 7936b40
Merge remote-tracking branch 'upstream/master' into feature/salted_pa…
lennartvdd 5acc2af
Merge branch 'master' of github.com:mishamx/yii-user into feature/sal…
lennartvdd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
class m121001_001625_userSalt extends CDbMigration | ||
{ | ||
public function safeUp() | ||
{ | ||
if (!Yii::app()->getModule('user')) { | ||
echo "\n\nAdd to console.php :\n" | ||
."'modules'=>array(\n" | ||
."...\n" | ||
." 'user'=>array(\n" | ||
." ... # copy settings from main config\n" | ||
." ),\n" | ||
."...\n" | ||
."),\n" | ||
."\n"; | ||
return false; | ||
} | ||
|
||
switch ($this->dbType()) { | ||
case "mysql": | ||
$this->addColumn(Yii::app()->getModule('user')->tableUsers,'salt',"VARCHAR(40) NULL DEFAULT NULL AFTER `password`"); | ||
break; | ||
case "sqlite": | ||
default: | ||
$this->addColumn(Yii::app()->getModule('user')->tableUsers,'salt',"VARCHAR(40) DEFAULT NULL"); | ||
break; | ||
} | ||
} | ||
|
||
public function safeDown() | ||
{ | ||
switch ($this->dbType()) { | ||
case "mysql": | ||
$this->dropColumn(Yii::app()->getModule('user')->tableUsers,'salt'); | ||
break; | ||
case "sqlite": | ||
|
||
$this->execute('ALTER TABLE `'.Yii::app()->getModule('user')->tableUsers.'` RENAME TO `'.__CLASS__.'_'.Yii::app()->getModule('user')->tableUsers.'`'); | ||
$this->createTable(Yii::app()->getModule('user')->tableUsers, array( | ||
"id" => "pk", | ||
"username" => "varchar(20) NOT NULL", | ||
"password" => "varchar(128) NOT NULL", | ||
"email" => "varchar(128) NOT NULL", | ||
"activkey" => "varchar(128) NOT NULL", | ||
"superuser" => "int(1) NOT NULL", | ||
"status" => "int(1) NOT NULL", | ||
"create_at" => "TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP", | ||
"lastvisit_at" => "TIMESTAMP", | ||
)); | ||
$this->execute('INSERT INTO `'.Yii::app()->getModule('user')->tableUsers.'` SELECT "id","username","password","email","activkey","superuser","status","create_at","lastvisit_at" FROM `'.__CLASS__.'_'.Yii::app()->getModule('user')->tableUsers.'`'); | ||
$this->dropTable(__CLASS__.'_'.Yii::app()->getModule('user')->tableUsers); | ||
|
||
break; | ||
} | ||
} | ||
|
||
public function dbType() | ||
{ | ||
list($type) = explode(':',Yii::app()->db->connectionString); | ||
echo "type db: ".$type."\n"; | ||
return $type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,7 @@ | |
} | ||
|
||
array_push($attributes, | ||
'password', | ||
'email', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is actually unrelated to the merge request, but I think it's a small security improvement. No one really has any business looking at user passwords, hashed or otherwise. Feel free to undo this change if you disagree, though. |
||
'activkey', | ||
'create_at', | ||
'lastvisit_at', | ||
array( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this unset() is somewhat important, because it makes sure this property is not changed in the database.
When an admin decides to change a users password, but does so by entering the old password (above statement evaluates to false), this property would hold that old password in plaintext form and the save() below would commit that to the database, causing a major security risk (exposing the admin's password) and effectively rendering the account useless because it would become impossible to login again with those credentials.
Ofcourse chances of that happening to another users account are small, but it may very well happen when updating his own account.