Skip to content

Define internal password policy typings #7446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions packages/auth/src/model/password_policy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* @license
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { PasswordPolicy, PasswordValidationStatus } from './public_types';

/**
* Internal typing of password policy that includes the schema version and methods for
* validating that a password meets the policy. The developer does not need access to
* these properties and methods, so they are excluded from the public typing.
*
* @internal
*/
export interface PasswordPolicyInternal extends PasswordPolicy {
/**
* Schema version of the password policy.
*/
readonly schemaVersion: number;
/**
* Validates the password against the policy.
* @param password Password to validate.
*/
validatePassword(password: string): PasswordValidationStatus;
Copy link
Contributor Author

@ch5zzy ch5zzy Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be 2 private helper methods (_checkLengthOptions and _checkCharacterOptions) defined in PasswordPolicyImpl which will implement this interface. The validatePassword method will call these helpers internally. I did not include this class in this PR to make this easier to review.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add public static annotation?

}

/**
* Internal typing of password validation status that is modifiable. This allows us to
* construct the validation status before returning it.
*
* @internal
*/
export interface PasswordValidationStatusInternal
extends PasswordValidationStatus {
/**
* Whether the password meets all requirements.
*/
isValid: boolean;
/**
* Whether the password meets the minimum password length.
*/
meetsMinPasswordLength?: boolean;
/**
* Whether the password meets the maximum password length.
*/
meetsMaxPasswordLength?: boolean;
/**
* Whether the password contains a lowercase letter, if required.
*/
containsLowercaseLetter?: boolean;
/**
* Whether the password contains an uppercase letter, if required.
*/
containsUppercaseLetter?: boolean;
/**
* Whether the password contains a numeric character, if required.
*/
containsNumericCharacter?: boolean;
/**
* Whether the password contains a non-alphanumeric character, if required.
*/
containsNonAlphanumericCharacter?: boolean;
/**
* The policy used to validate the password.
*/
passwordPolicy: PasswordPolicy;
}