black friday sale

Custom Fields
Re-Envisioned
Support General Disable password field from encrpyting value

  • Creator
    Topic
  • #21172
    Resolved Content Pilot
    Participant

    I am looking for a hybrid of the password field and the text field. Would it be possible to (maybe add a filter or custom attribute) so that the admin input obfuscate the value entered by the user but, on save, does not encrypt the value in the database? That would make it a little bit harder to store license keys in the admin. They are plainly readable in the database, sure, but they are not readable to a normal user while inside the WP admin. I could see this either being a modification on the password field to not encrypt the value or on the text field to obfuscate the value entered.

    Is there anything out there right now to satisfy my requirements?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #21180
    Long Nguyen
    Moderator

    Hi,

    The field password always encrypts value when saving to the database, it cannot and do not recommend changing the purpose of this field. I think you can use two fields to achieve this goal.
    – Field password: let user type the license key.
    – Field hidden: get the value from field password when user types and save the text value in the database (use some jQuery code).

    Very easy to read the text with the hidden field.

    #21202
    Content Pilot
    Participant

    I follow this tutorial and created my own field–License. It is a password input but saves as normal text in the admin.

    https://docs.metabox.io/custom-field-type/

    if ( class_exists( 'RWMB_Field' ) ) {
            /**
         * Metabox Field
         * 
         * Create new field to store access token in admin.
         *<br />
         * Obfuscates the view to the end user but saves as plain text in the database.
         * 
         * @since 5.1.0
         */
        class RWMB_License_Field extends RWMB_Field {
            /**
             * Render the field
             *
             * @param string $meta Value from input.
             * @param array $field Field data.
             * @return string
             * @since 5.1.0
             */
            public static function html( $meta, $field ) {
                return sprintf(
                    '<input type="password" name="%s" id="%s" value="%s" size="%s">',
                    $field['field_name'],
                    $field['id'],
            $meta,
            $field['size']
                );
            }
        }
    }
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.