is_activated = get_user_meta( $user->ID,self::BACKUP_CODE_START, true );
$this->description = empty( $this->is_activated )
? __( 'Generate non-expirable backup codes that can be used to log in once.', 'wpdef' )
: __( 'Each backup code can only be used to log in once.', 'wpdef' );
}
/**
* Get the name of the provider.
*
* @return string
*/
public function get_label() {
return __( 'Backup Codes', 'wpdef' );
}
/**
* @return string
*/
public function get_login_label() {
return $this->get_label();
}
/**
* @return string
*/
public function get_user_label() {
return __( 'Backup codes', 'wpdef' );
}
/**
* Get the desc of the provider.
*
* @return string
*/
public function get_description() {
return $this->description;
}
/**
* Whether this 2FA provider is configured and codes are available for the user specified.
*
* @param \WP_User $user
*
* @return bool
*/
public function is_available_for_user( $user ) {
// Does this user have available codes?
if ( 0 < self::get_unused_codes_for_user( $user ) ) {
return true;
}
return false;
}
public function authentication_form() {
?>
get_label(); ?>
ID, self::BACKUP_CODE_VALUES, true );
if ( is_array( $backup_codes ) && ! empty( $backup_codes ) ) {
return count( $backup_codes );
}
return 0;
}
/**
* Generate a random string for an auth code.
*
* @return string
*/
private static function get_code() {
$code = '';
$chars = self::BACKUP_CODE_CHARACTERS;
for ( $i = 0; $i < self::BACKUP_CODE_SIZE; $i++ ) {
$code .= substr( $chars, wp_rand( 0, strlen( $chars ) - 1 ), 1 );
}
return $code;
}
/**
* Show an admin notice when backup codes have run out.
*/
public function admin_notices() {
$user = wp_get_current_user();
if ( ! is_object( $user ) ) {
return;
}
// Is User role from common list checked?
if ( empty( array_intersect( $user->roles, $this->get_model()->user_roles ) ) ) {
return;
}
// Return if the provider is not enabled.
if ( ! in_array( self::$slug, $this->get_component()->get_enabled_providers_for_user( $user->ID ), true ) ) {
return;
}
// Return if we are not out of codes.
if ( $this->is_available_for_user( $user ) ) {
return;
}
?>