@obliczeniowo/elementary
Version:
Library made in Angular version 20
98 lines (93 loc) • 6.75 kB
JavaScript
import * as i0 from '@angular/core';
import { Input, ChangeDetectionStrategy, Component, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
class PasswordStrengthComponent {
change;
password = '';
height = 1;
weryWeak = Math.pow(26, 10);
weak = Math.pow(26 + 26, 10);
strong = Math.pow(26 + 26 + 10, 10);
weryStrong = Math.pow(26 + 26 + 10 + 30, 10);
translations = {
weryWeak: 'wery weak',
weak: 'weak',
strong: 'strong',
weryStrong: 'wery strong'
};
id;
strengthType = 'weryWeak';
constructor(change) {
this.change = change;
const generate = () => `Password_${Math.floor(Math.random() * 100000000)}`;
this.id = generate();
while (document.querySelector('#' + this.id)) {
this.id = generate();
}
}
getK() {
const strength = this.getStrength();
if (strength < this.weryWeak) {
this.strengthType = 'weryWeak';
return 0.4 * strength / this.weryWeak;
}
else if (strength < this.weak) {
this.strengthType = 'weak';
return 0.4 + 0.4 * strength / this.weak;
}
else if (strength < this.strong) {
this.strengthType = 'strong';
return 0.8 + 0.1 * strength / this.strong;
}
else if (strength < this.weryStrong) {
this.strengthType = 'weryStrong';
return 0.9 + 0.1 * strength / this.weryStrong;
}
this.strengthType = 'weryStrong';
return 1;
}
getStrength() {
const hasLowerCase = /[a-z]/.test(this.password);
const hasUpperCase = /[A-Z]/.test(this.password);
const hasNumbers = /[0-9]/.test(this.password);
const hasSpecialChars = /[^a-zA-Z0-9\s]/.test(this.password);
const hasWhiteSpace = /[ \t]/.test(this.password);
return Math.pow((hasLowerCase && 26 || 0) +
(hasUpperCase && 26 || 0) +
(hasNumbers && 10 || 0) +
(hasSpecialChars && 30 || 0) +
(hasWhiteSpace && 2 || 0), this.password.length);
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: PasswordStrengthComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.0.4", type: PasswordStrengthComponent, isStandalone: false, selector: "obl-password-strength", inputs: { password: "password" }, ngImport: i0, template: "<svg height=\"5\" viewBox=\"0 0 52.916665 1.3229167\">\n <defs id=\"defs2\">\n <clipPath [attr.id]=\"id\">\n <rect [attr.width]=\"100 * getK() + '%'\" height=\"1.3229166\" x=\"0\" y=\"0\" />\n </clipPath>\n </defs>\n <path\n class=\"background\"\n d=\"M 0,0 V 1.3229166 H 11.90625 V 0 Z M 13.229167,0 V 1.3229166 H 25.135416 V 0 Z m 13.229166,0 v 1.3229166 h 11.90625 V 0 Z M 39.6875,0 v 1.3229166 h 6.614583 V 0 Z m 7.937499,0 v 1.3229166 h 5.291667 V 0 Z\"\n />\n <g [attr.clip-path]=\"'url(#' + id + ')'\">\n <path class=\"weak\" d=\"M -1.666668e-8,0 V 1.3229167 H 11.90625 V 0 Z\" />\n <path class=\"weak\" d=\"m 13.229167,0 v 1.3229167 h 11.90625 V 0 Z\" />\n <path class=\"weak\" d=\"m 26.458333,0 v 1.3229167 h 11.90625 V 0 Z\" />\n <path class=\"strong\" d=\"m 39.6875,0 v 1.3229167 h 6.614583 V 0 Z\" />\n <path class=\"wery-strong\" d=\"m 47.625,0 v 1.3229167 h 5.291666 V 0 Z\" />\n </g>\n</svg>\n{{ translations[strengthType] }}", styles: [".background{fill:#f2f2f2}.weak{fill:#c20000}.strong{fill:orange}.wery-strong{fill:#02bd02}:host{padding:10px;display:flex;flex-direction:column;align-items:center;width:200px;font-size:12px}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: PasswordStrengthComponent, decorators: [{
type: Component,
args: [{ selector: 'obl-password-strength', changeDetection: ChangeDetectionStrategy.OnPush, standalone: false, template: "<svg height=\"5\" viewBox=\"0 0 52.916665 1.3229167\">\n <defs id=\"defs2\">\n <clipPath [attr.id]=\"id\">\n <rect [attr.width]=\"100 * getK() + '%'\" height=\"1.3229166\" x=\"0\" y=\"0\" />\n </clipPath>\n </defs>\n <path\n class=\"background\"\n d=\"M 0,0 V 1.3229166 H 11.90625 V 0 Z M 13.229167,0 V 1.3229166 H 25.135416 V 0 Z m 13.229166,0 v 1.3229166 h 11.90625 V 0 Z M 39.6875,0 v 1.3229166 h 6.614583 V 0 Z m 7.937499,0 v 1.3229166 h 5.291667 V 0 Z\"\n />\n <g [attr.clip-path]=\"'url(#' + id + ')'\">\n <path class=\"weak\" d=\"M -1.666668e-8,0 V 1.3229167 H 11.90625 V 0 Z\" />\n <path class=\"weak\" d=\"m 13.229167,0 v 1.3229167 h 11.90625 V 0 Z\" />\n <path class=\"weak\" d=\"m 26.458333,0 v 1.3229167 h 11.90625 V 0 Z\" />\n <path class=\"strong\" d=\"m 39.6875,0 v 1.3229167 h 6.614583 V 0 Z\" />\n <path class=\"wery-strong\" d=\"m 47.625,0 v 1.3229167 h 5.291666 V 0 Z\" />\n </g>\n</svg>\n{{ translations[strengthType] }}", styles: [".background{fill:#f2f2f2}.weak{fill:#c20000}.strong{fill:orange}.wery-strong{fill:#02bd02}:host{padding:10px;display:flex;flex-direction:column;align-items:center;width:200px;font-size:12px}\n"] }]
}], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { password: [{
type: Input
}] } });
class PasswordModule {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: PasswordModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.4", ngImport: i0, type: PasswordModule, declarations: [PasswordStrengthComponent], imports: [CommonModule], exports: [PasswordStrengthComponent] });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: PasswordModule, imports: [CommonModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: PasswordModule, decorators: [{
type: NgModule,
args: [{
declarations: [
PasswordStrengthComponent
],
imports: [
CommonModule
],
exports: [
PasswordStrengthComponent
]
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { PasswordModule, PasswordStrengthComponent };
//# sourceMappingURL=obliczeniowo-elementary-password.mjs.map