# profile-builder/2.0.4/front-end/default-fields/password/password.php

User Profile Builder – Beautiful User Registration Forms, User Profiles &amp; User Role Editor, version 2.0.4. 63 lines.

- Page: https://pluginprobe.com/plugins/profile-builder/2.0.4/code/front-end/default-fields/password/password.php
- Raw: https://pluginprobe.com/plugins/profile-builder/2.0.4/raw/front-end/default-fields/password/password.php
- Modified: 2014-10-21T13:22:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/profile-builder/2.0.4/code/front-end/default-fields/password/password.php#L10-L20`.

```php
<?php
/* handle field output */
function wppb_password_handler( $output, $form_location, $field, $user_id, $field_check_errors, $request_data ){
	$item_title = apply_filters( 'wppb_'.$form_location.'_password_item_title', wppb_icl_t( 'plugin profile-builder-pro', 'default_field_'.$field['id'].'_title_translation', $field['field-title'] ) );
	$item_description = wppb_icl_t( 'plugin profile-builder-pro', 'default_field_'.$field['id'].'_description_translation', $field['description'] );

	if ( $form_location != 'back_end' ){
		$error_mark = ( ( $field['required'] == 'Yes' ) ? '<span class="wppb-required" title="'.wppb_required_field_error($field["field-title"]).'">*</span>' : '' );
					
		if ( array_key_exists( $field['id'], $field_check_errors ) )
			$error_mark = '<img src="'.WPPB_PLUGIN_URL.'assets/images/pencil_delete.png" title="'.wppb_required_field_error($field["field-title"]).'"/>';

        $output = '
			<label for="passw1">' . $item_title.$error_mark . '</label>
			<input class="text-input" name="passw1" maxlength="'. apply_filters( 'wppb_maximum_character_length', 70 ) .'" type="password" id="passw1" value="" autocomplete="off" />';
        if( !empty( $item_description ) )
            $output .= '<span class="wppb-description-delimiter">'.$item_description.' '.wppb_password_length_text().'</span>';
        else
            $output .= '<span class="wppb-description-delimiter">'.wppb_password_length_text().'</span>';

        /* if we have active the password strength checker */
        $output .= wppb_password_strength_checker_html();

	}
		
	return apply_filters( 'wppb_'.$form_location.'_password', $output, $form_location, $field, $user_id, $field_check_errors, $request_data );
}
add_filter( 'wppb_output_form_field_default-password', 'wppb_password_handler', 10, 6 );

/* handle field validation */
function wppb_check_password_value( $message, $field, $request_data, $form_location ){
	if ( $form_location == 'register' ){
		if ( ( isset( $request_data['passw1'] ) && ( trim( $request_data['passw1'] ) == '' ) ) && ( $field['required'] == 'Yes' ) )
			return wppb_required_field_error($field["field-title"]);
		
		elseif ( !isset( $request_data['passw1'] ) && ( $field['required'] == 'Yes' ) )
			return wppb_required_field_error($field["field-title"]);
	}

    if ( trim( $request_data['passw1'] ) != '' ){
        $wppb_generalSettings = get_option( 'wppb_general_settings' );

        if( wppb_check_password_length( $request_data['passw1'] ) )
            return __( "<br/>The password must have the minimum length of ". $wppb_generalSettings['minimum_password_length'] ." characters", "profilebuilder" );


        if( wppb_check_password_strength() ){
            return __( "<br/>The password must have a minimum strength of ". wppb_check_password_strength(), "profilebuilder" );
        }
    }

    return $message;
}
add_filter( 'wppb_check_form_field_default-password', 'wppb_check_password_value', 10, 4 );

/* handle field save */
function wppb_userdata_add_password( $userdata, $global_request ){
	if ( isset( $global_request['passw1'] ) && ( trim( $global_request['passw1'] ) != '' ) )
		$userdata['user_pass'] = trim( $global_request['passw1'] );
	
	return $userdata;
}
add_filter( 'wppb_build_userdata', 'wppb_userdata_add_password', 10, 2 );
```
