1
0
mirror of https://github.com/kremalicious/krtmn.git synced 2024-12-22 17:23:33 +01:00
krtmn/includes/auth.php

63 lines
1.9 KiB
PHP
Raw Normal View History

2012-02-26 03:28:54 +01:00
<?php
// No direct call
if( !defined( 'YOURLS_ABSPATH' ) ) die();
2016-04-13 22:02:46 +02:00
$auth = yourls_is_valid_user();
2012-02-26 03:28:54 +01:00
if( $auth !== true ) {
// API mode,
if ( yourls_is_API() ) {
$format = ( isset($_REQUEST['format']) ? $_REQUEST['format'] : 'xml' );
$callback = ( isset($_REQUEST['callback']) ? $_REQUEST['callback'] : '' );
yourls_api_output( $format, array(
'simple' => $auth,
'message' => $auth,
'errorCode' => 403,
'callback' => $callback,
) );
// Regular mode
} else {
yourls_login_screen( $auth );
}
die();
}
2016-04-13 22:02:46 +02:00
yourls_do_action( 'auth_successful' );
/*
* The following code is a shim that helps users store passwords securely in config.php
* by storing a password hash and removing the plaintext.
*
* TODO: Remove this once real user management is implemented
*/
// Did we just fail at encrypting passwords ?
if ( isset( $_GET['dismiss'] ) && $_GET['dismiss'] == 'hasherror' ) {
yourls_update_option( 'defer_hashing_error', time() + 86400 * 7 ); // now + 1 week
} else {
// Encrypt passwords that are clear text
if ( !defined( 'YOURLS_NO_HASH_PASSWORD' ) && yourls_has_cleartext_passwords() ) {
$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' ) )
yourls_delete_option( 'defer_hashing_error' );
} else {
// It failed, display message for first time or if last time was a week ago
if ( time() > yourls_get_option( 'defer_hashing_error' ) or !yourls_get_option( 'defer_hashing_error' ) ) {
$message = yourls_s( 'Could not auto-encrypt passwords. Error was: "%s".', $hash );
$message .= ' ';
$message .= yourls_s( '<a href="%s">Get help</a>.', 'http://yourls.org/userpassword' );
$message .= '</p><p>';
$message .= yourls_s( '<a href="%s">Click here</a> to dismiss this message for one week.', '?dismiss=hasherror' );
yourls_add_notice( $message );
}
}
}
}