Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
with comment solution in Clear category for Acceptable Password V by Sim0000
import assert from "assert";
function isAcceptablePassword(password: string): boolean {
// C1: the length should be bigger than 6;
// C2: should contain at least one digit, but cannot consist of just digits.
// C3: if the password is longer than 9 - previous rule (about one digit), is not required.
// C4: a string should not contain the word "password" in any case.
const c1 = password.length > 6;
const c2 = /\d/.test(password) && !/^\d*$/.test(password);
const c3 = password.length > 9;
const c4 = !password.toLowerCase().includes('password');
return c1 && (c2 || c3) && c4;
}
// These "asserts" are used for self-checking
// These "asserts" are used for self-checking
// These "asserts" are used for self-checking
// These "asserts" are used for self-checking
assert.strictEqual(isAcceptablePassword("short"), false);
assert.strictEqual(isAcceptablePassword("short54"), true);
assert.strictEqual(isAcceptablePassword("muchlonger"), true);
assert.strictEqual(isAcceptablePassword("ashort"), false);
assert.strictEqual(isAcceptablePassword("muchlonger5"), true);
assert.strictEqual(isAcceptablePassword("sh5"), false);
assert.strictEqual(isAcceptablePassword("1234567"), false);
assert.strictEqual(isAcceptablePassword("12345678910"), true);
assert.strictEqual(isAcceptablePassword("password12345"), false);
assert.strictEqual(isAcceptablePassword("PASSWORD12345"), false);
assert.strictEqual(isAcceptablePassword("pass1234word"), true);
Nov. 13, 2022