Skip to content

Commit

Permalink
Pass parameter to yourls_hash_passwords_now(). Will make tests easier.
Browse files Browse the repository at this point in the history
  • Loading branch information
ozh committed Sep 5, 2013
1 parent 56f1b3b commit 5d2b954
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion includes/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

// Encrypt passwords that are clear text
if ( !defined( 'YOURLS_NO_HASH_PASSWORD' ) && yourls_has_cleartext_passwords() ) {
$hash = yourls_hash_passwords_now();
$hash = yourls_hash_passwords_now( YOURLS_CONFIGFILE );
if ( $hash === true ) {
// Hashing succesful. Remove flag from DB if any.
if( yourls_get_option( 'defer_hashing_error' ) )
Expand Down
13 changes: 7 additions & 6 deletions includes/functions-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,19 @@ function yourls_check_password_hash( $user, $submitted_password ) {
* Overwrite plaintext passwords in config file with phpassed versions.
*
* @since 1.7
* @param string $config_file Full path to file
* @return true if overwrite was successful, an error message otherwise
*/
function yourls_hash_passwords_now() {
function yourls_hash_passwords_now( $config_file ) {
global $yourls_user_passwords;

if( !is_readable( YOURLS_CONFIGFILE ) )
if( !is_readable( $config_file ) )
return 'cannot read file'; // not sure that can actually happen...

if( !is_writable( YOURLS_CONFIGFILE ) )
if( !is_writable( $config_file ) )
return 'cannot write file';

$configdata = file_get_contents( YOURLS_CONFIGFILE );
$configdata = file_get_contents( $config_file );
if( $configdata == false )
return 'could not read file';

Expand Down Expand Up @@ -186,10 +187,10 @@ function yourls_hash_passwords_now() {
if( $to_hash == 0 )
return true; // There was no password to encrypt

$success = file_put_contents( YOURLS_CONFIGFILE, $configdata );
$success = file_put_contents( $config_file, $configdata );
if ( $success === FALSE ) {
global $ydb;
$ydb->debug_log[] = "Failed writing to " . YOURLS_CONFIGFILE;
$ydb->debug_log[] = "Failed writing to " . $config_file;
return 'could not write file';
}
return true;
Expand Down

0 comments on commit 5d2b954

Please sign in to comment.