isUnlocked() ) {
http_response_code( 404 );
}
}
public function isUnlocked(): bool {
return apply_filters(
Plugin::FILTER_IS_UNLOCKED,
isset($_GET[$this->plugin->environment->getParamName()])
);
}
public function login_form() {
if (!$this->isUnlocked()) {
// The status code is set on login_init, before the page starts printing.
$waitForSeconds = $this->plugin->environment->getWaitForSeconds();
$paramName = $this->plugin->environment->getParamName();
if ( WP_DEBUG ) {
echo "";
}
$img = esc_url( get_admin_url() . 'images/spinner.gif' );
// --- START
echo "

";
// ------ wait for secure login ---
echo "
";
printf( "
%s
", esc_html__( "Securing login...", 'a-little-more-secure' ) );
$text = sprintf(
esc_html__( "%s seconds left", 'a-little-more-secure' ),
"
" . (int) $waitForSeconds . ""
);
echo "
$text
";
echo "
";
// ------ redirect to login ---
printf( "
%s
", esc_html__( "Redirect to secure login...", 'a-little-more-secure' ) );
// --- END
echo "
";
if ( WP_DEBUG ) {
echo "";
}
?>
🔒 %s", esc_html__( "Your login is a little more secure.", 'a-little-more-secure' ) );
$this->nonceField();
}
}
public function nonceField() {
wp_nonce_field( Plugin::NONCE_ACTION, Plugin::NONCE_NAME );
}
public function login_action() {
if ( ( $_SERVER['REQUEST_METHOD'] ?? '' ) !== 'POST' ) {
return;
}
// Anything but a string - an array from "nonce[]=x", for instance - is not
// a nonce, so it is rejected before wp_verify_nonce() ever sees it.
$nonce = $_POST[ Plugin::NONCE_NAME ] ?? null;
$nonce = is_string( $nonce ) ? sanitize_text_field( wp_unslash( $nonce ) ) : '';
if ( ! wp_verify_nonce( $nonce, Plugin::NONCE_ACTION ) ) {
wp_die(
esc_html__( "Sorry, this feels not very secure.", 'a-little-more-secure' ),
esc_html__( "🔒", 'a-little-more-secure' ),
[
"response" => 400,
"link_text" => esc_html__( "Goto login form", 'a-little-more-secure' ),
"link_url" => wp_login_url(),
]
);
}
}
public function login_form_bottom( $content, $args ) {
// other login forms that are not on /wp-login.php are ignored by this plugin
ob_start();
$this->nonceField();
$field = ob_get_contents();
ob_end_clean();
return $content . $field;
}
}