Password

Improve this page

Overview

The password field creates a simple password input. The password is encrypted by wp_hash_password() before saving into the database to make sure it’s safe.

Screenshot

password

Settings

Besides the common settings, this field has the following specific settings:

Name Description
size Input size. Default 30. Optional.

Sample code

array(
    'name' => 'Password',
    'id'   => 'password',
    'type' => 'password',
),

Data

This field saves the encrypted password in the database for a better security. The password is encrypted by wp_hash_password() function.

Template usage

As the password is encrypted in the database, you cannot get the original password via code. There’s no reversing function that can turn a password hash into the original one. Otherwise, it will be insecure.

Instead of trying to get the original password, you should check the saved password is correct, like this:

$value = rwmb_meta( $field_id );
if ( $value === wp_hash_password( 'password to check' ) ) {
    echo 'Password is correct';
}

Read more about rwmb_meta().