4, 'headers' => array( 'Add-Padding' => 'true' ), 'user-agent' => 'WordPress Login Guard', ) ); if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { return null; } return self::count_in_response( wp_remote_retrieve_body( $response ), substr( $hash, 5 ) ); } private static function error_message( $count ) { return sprintf( /* translators: %s: how often the password appears in known data breaches */ __( 'This password appears in known data breaches (%s times) and is easy to guess. Please choose a different one.', '360-orbit-login-guard' ), number_format_i18n( $count ) ); } /** * Profil bearbeiten oder Benutzer anlegen im Backend. * * @param WP_Error $errors Fehler. * @param bool $update Ob ein bestehendes Konto bearbeitet wird. * @param object $user Daten des Formulars, mit user_pass bei neuem Passwort. */ public static function check_profile_update( $errors, $update, $user ) { if ( empty( $user->user_pass ) || $errors->has_errors() ) { return; } $count = self::breach_count( $user->user_pass ); if ( $count ) { $errors->add( 'wp360_lg_pwned_password', self::error_message( $count ), array( 'form-field' => 'pass1' ) ); } } /** * Formular „Neues Passwort festlegen“ nach „Passwort vergessen“. * * @param WP_Error $errors Fehler. * @param WP_User|WP_Error $user Konto. */ public static function check_password_reset( $errors, $user ) { $pass = isset( $_POST['pass1'] ) ? (string) wp_unslash( $_POST['pass1'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- WordPress prueft das Reset-Formular selbst; ein Passwort wird nicht veraendert. if ( '' === $pass || $errors->has_errors() || is_wp_error( $user ) ) { return; } $count = self::breach_count( $pass ); if ( $count ) { $errors->add( 'wp360_lg_pwned_password', self::error_message( $count ) ); } } /** Administratoren: Passwort bei der Anmeldung pruefen, bei Treffer Hinweis merken. */ public static function check_on_login( $username, $user ) { $pass = isset( $_POST['pwd'] ) ? (string) wp_unslash( $_POST['pwd'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- das Anmeldeformular hat keine Nonce; das Passwort wird nur gehasht. if ( '' === $pass || ! $user instanceof WP_User || ! user_can( $user, 'manage_options' ) ) { return; } $count = self::breach_count( $pass ); if ( null === $count ) { return; } if ( $count > 0 ) { update_user_meta( $user->ID, self::FLAG_META, $count ); } else { delete_user_meta( $user->ID, self::FLAG_META ); } } public static function notice() { $user_id = get_current_user_id(); $count = $user_id ? (int) get_user_meta( $user_id, self::FLAG_META, true ) : 0; if ( $count < 1 ) { return; } printf( '
%s %s