Password

Password displays strength indicator for password fields.


import { PasswordModule } from 'primeng/password';

Two-way value binding is defined using ngModel.


<p-password [(ngModel)]="value" [feedback]="false" />

Password can also be used with reactive forms. In this case, the formControlName property is used to bind the component to a form control.


<form [formGroup]="formGroup">
    <p-password formControlName="value" [feedback]="false" />
</form>

Strength meter is displayed as a popup while a value is being entered.


<p-password [(ngModel)]="value" />

Labels are translated at component level by promptLabel, weakLabel, mediumLabel and strongLabel properties. In order to apply global translations for all Password components in the application, refer to the locale


<p-password [(ngModel)]="value" promptLabel="Choose a password" weakLabel="Too simple" mediumLabel="Average complexity" strongLabel="Complex password" />

When toggleMask is present, an icon is displayed to show the value as plain text.


<p-password [(ngModel)]="value" [toggleMask]="true" />

3 templates are included to customize the overlay. These are header, content and footer. Note that content overrides the default meter.


<p-password [(ngModel)]="value" autocomplete="off">
    <ng-template pTemplate="header">
        <div class="font-semibold text-xm mb-4">Pick a password</div>
    </ng-template>
    <ng-template pTemplate="footer">
        <p-divider />
        <ul class="pl-2 ml-2 my-0 leading-normal">
            <li>At least one lowercase</li>
            <li>At least one uppercase</li>
            <li>At least one numeric</li>
            <li>Minimum 8 characters</li>
        </ul>
    </ng-template>
</p-password>

A floating label appears on top of the input field when focused. Visit FloatLabel documentation for more information.


<p-floatlabel>
    <p-password [(ngModel)]="value1" inputId="over_label" />
    <label for="over_label">Over Label</label>
</p-floatlabel>

<p-floatlabel variant="in">
    <p-password [(ngModel)]="value2" inputId="in_label" />
    <label for="in_label">In Label</label>
</p-floatlabel>

<p-floatlabel variant="on">
    <p-password [(ngModel)]="value3" inputId="on_label" />
    <label for="on_label">On Label</label>
</p-floatlabel>

IftaLabel is used to create infield top aligned labels. Visit IftaLabel documentation for more information.


<p-iftalabel>
    <p-password [(ngModel)]="value" inputId="password" />
    <label for="password">Password</label>
</p-iftalabel>

Password provides small and large sizes as alternatives to the base.


<p-password [(ngModel)]="value1" type="text" size="small" placeholder="Small" />
<p-password [(ngModel)]="value2" type="text" placeholder="Normal" />
<p-password [(ngModel)]="value3" type="text" size="large" placeholder="Large" />

Specify the variant property as filled to display the component with a higher visual emphasis than the default outlined style.


<p-password [(ngModel)]="value" [feedback]="false" variant="filled" />

Invalid state style is added using the ng-invalid and ng-dirty class to indicate a failed validation.


<p-password [(ngModel)]="value" class="ng-invalid ng-dirty" />

When disabled is present, the element cannot be edited and focused.


<p-password [(ngModel)]="value" [disabled]="true" placeholder="Disabled" />

Screen Reader

Value to describe the component can either be provided via label tag combined with id prop or using ariaLabelledBy, ariaLabel props. Screen reader is notified about the changes to the strength of the password using a section that has aria-live while typing.


<label for="pwd1">Password</label>
<p-password inputId="pwd1" />

<span id="pwd2">Password</span>
<p-password ariaLabelledBy="pwd2" />

<p-password ariaLabel="Password" />

Keyboard Support

KeyFunction
tabMoves focus to the input.
escapeHides the strength meter if open.