Skip to content

Commit

Permalink
Mar 26 21:01
Browse files Browse the repository at this point in the history
Finished logic and started work with meter
  • Loading branch information
yidu2008 committed Mar 27, 2020
1 parent 98e68eb commit ca35a8c
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 14 deletions.
20 changes: 16 additions & 4 deletions src/app/tab2/tab2.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@
</ion-item>
</p>
<ion-button expand="block" (click)="onRunProgram()">Run Program</ion-button>
<p>
Please note that although our program will only test a few things, keep
these things in mind:
</p>
<p>
Never, ever, ever use your personal information.
</p>
<p>
Try not to use dictionary words.
</p>
<p>
Strength Meter:
</p>
<div
class="meter-display"
[ngStyle]="{'background-color': meterStrengthColor}"
></div>
<div class="meter-display-container">
<div
class="meter-display"
[ngStyle]="{'background-color': meterStrengthColor, 'width': meterStrengthWidth+'%'}"
></div>
</div>
</ion-content>
7 changes: 5 additions & 2 deletions src/app/tab2/tab2.page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ ion-content ion-toolbar {
--background: translucent;
}

.meter-display {
height: 1em;
.meter-display-container {
border: 1px solid black;
background-color: grey;
.meter-display {
height: 1em;
}
}
174 changes: 166 additions & 8 deletions src/app/tab2/tab2.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ToastController } from "@ionic/angular";
export class Tab2Page {
public password = new FormControl("");
public meterStrengthColor = "darkgreen";
public meterStrengthWidth = 0;

constructor(public toastController: ToastController) {}

Expand All @@ -19,36 +20,193 @@ export class Tab2Page {

console.log(this.password.value.length);

if (this.password.value.length < 7) {
if (this.password.value.length < 7 && this.password.value.length > 0) {
console.log("Your password is very short!");
alertMessages.push("Your password is very short!");
this.meterStrengthWidth = this.meterStrengthWidth + 12.5;
}
this.meterStrengthWidth = 5;
if (this.password.value.length > 6 && this.password.value.length < 12) {
console.log("Your password is short!");
alertMessages.push("Your password is short!");
alertMessages.push("Your password is short!");
this.meterStrengthWidth = this.meterStrengthWidth + 25;
}
if (this.password.value.length > 11) {
console.log("Your password is long enough. Now, will you remember it?");
alertMessages.push(
"Your password is long enough. Now, will you remember it?"
);
this.meterStrengthWidth = this.meterStrengthWidth + 50;
}
if (this.password.value.length < 1) {
console.log("You didn't enter a password!");
alertMessages.push("You didn't enter a password!");
this.meterStrengthWidth = this.meterStrengthWidth + 0;
}
if (/^[a-zA-Z]+$/gi.test(this.password.value)) {
console.log("Your password contains only letters. This isn't good!");
alertMessages.push(
"Your password contains only letters. This isn't good!"
);
this.meterStrengthWidth = this.meterStrengthWidth + 25;
}
if (alertMessages.length > 0) {
const toast = await this.toastController.create({
message: alertMessages.join("\n"),
duration: 5000
});
toast.present();
if (/^[a-z]+$/g.test(this.password.value)) {
console.log(
"Your password contains only lowercase letters. Try adding uppercase letters!"
);
alertMessages.push(
"Your password contains only lowercase letters. Try adding uppercase letters!"
);
this.meterStrengthWidth = this.meterStrengthWidth + 25;
}
if (/^[A-Z]+$/g.test(this.password.value)) {
console.log(
"Your password contains only uppercase letters. Try adding lowercase letters!"
);
alertMessages.push(
"Your password contains only uppercase letters. Try adding lowercase letters!"
);
this.meterStrengthWidth = this.meterStrengthWidth + 25;
}
if (/^[0-9]+$/g.test(this.password.value)) {
console.log("Your password contains only numbers. This isn't good!");
alertMessages.push(
"Your password contains only numbers. This isn't good!"
);
this.meterStrengthWidth = this.meterStrengthWidth + 25;
if (/^[a-zA-Z0-9!-)]+$/g.test(this.password.value)) {
console.log(
"Your password contains good content. Now, will you remember it?"
);
alertMessages.push(
"Your password contains good content. Now, will you remember it?"
);
this.meterStrengthWidth = this.meterStrengthWidth + 50;
}
if (/password/gi.test(this.password.value)) {
console.log(
"Your password contains the word password. This is a very bad decision!"
);
alertMessages.push(
"Your password contains the word password. This is a very bad decision!"
);
}
if (/^123456+$/gi.test(this.password.value)) {
console.log(
"Your password is 123456, the most common password. This is a very unsecure password!"
);
alertMessages.push(
"Your password is 123456, the most common password. This is a very unsecure password!"
);
this.meterStrengthWidth = this.meterStrengthWidth - 100;
}

if (/^123456789+$/gi.test(this.password.value)) {
console.log(
"Your password is 123456789, the 2nd most common password. This is a very unsecure password!"
);
alertMessages.push(
"Your password is 123456789, the 2nd most common password. This is a very unsecure password!"
);
this.meterStrengthWidth = this.meterStrengthWidth - 100;
}
if (/^qwerty+$/gi.test(this.password.value)) {
console.log(
"Your password is qwerty, the 3rd most common password. This is a very unsecure password!"
);
alertMessages.push(
"Your password is qwerty, the 3rd most common password. This is a very unsecure password!"
);
this.meterStrengthWidth = this.meterStrengthWidth - 100;
}
if (/^password+$/gi.test(this.password.value)) {
console.log(
"Your password is password, the 4th most common password. This is a very unsecure password!"
);
alertMessages.push(
"Your password is password, the 4th most common password. This is a very unsecure password!"
);
this.meterStrengthWidth = this.meterStrengthWidth - 100;
}
if (/^1234567+$/gi.test(this.password.value)) {
console.log(
"Your password is 1234567, the 5th most common password. This is a very unsecure password!"
);
alertMessages.push(
"Your password is 1234567, the 5th most common password. This is a very unsecure password!"
);
this.meterStrengthWidth = this.meterStrengthWidth - 100;
}
if (/^12345678+$/gi.test(this.password.value)) {
console.log(
"Your password is 12345678, the 6th most common password. This is a very unsecure password!"
);
alertMessages.push(
"Your password is 12345678, the 6th most common password. This is a very unsecure password!"
);
this.meterStrengthWidth = this.meterStrengthWidth - 100;
}
if (/^12345+$/gi.test(this.password.value)) {
console.log(
"Your password is 12345, the 7th most common password. This is a very unsecure password!"
);
alertMessages.push(
"Your password is 12345, the 7th most common password. This is a very unsecure password!"
);
this.meterStrengthWidth = this.meterStrengthWidth - 100;
}
if (/^iloveyou+$/gi.test(this.password.value)) {
console.log(
"Your password is iloveyou, the 8th most common password. This is a very unsecure password!"
);
alertMessages.push(
"Your password is iloveyou, the 8th most common password. This is a very unsecure password!"
);
this.meterStrengthWidth = this.meterStrengthWidth - 100;
}
if (/^111111+$/gi.test(this.password.value)) {
console.log(
"Your password is 111111, the 9th most common password. This is a very unsecure password!"
);
alertMessages.push(
"Your password is 111111, the 9th most common password. This is a very unsecure password!"
);
this.meterStrengthWidth = this.meterStrengthWidth - 100;
}
if (/^123123+$/gi.test(this.password.value)) {
console.log(
"Your password is 123123, the 10th most common password. This is a very unsecure password!"
);
alertMessages.push(
"Your password is 123123, the 10th most common password. This is a very unsecure password!"
);
this.meterStrengthWidth = this.meterStrengthWidth - 100;
}
if (alertMessages.length > 0) {
const toast = await this.toastController.create({
message: alertMessages.join("\n"),
duration: 5000
});
toast.present();
}
if (this.meterStrengthWidth === 100) {
this.meterStrengthColor = "darkgreen";
}
if (this.meterStrengthWidth < 100 && this.meterStrengthWidth > 75) {
this.meterStrengthColor = "green";
}
if (this.meterStrengthWidth < 75 && this.meterStrengthWidth > 50) {
this.meterStrengthColor = "yellow";
}
if (this.meterStrengthWidth < 50 && this.meterStrengthWidth > 25) {
this.meterStrengthColor = "orange";
}
if (this.meterStrengthWidth < 25 && this.meterStrengthWidth > 10) {
this.meterStrengthColor = "red";
}
if (this.meterStrengthWidth < 10) {
this.meterStrengthColor = "darkred";
}
}
}
}

0 comments on commit ca35a8c

Please sign in to comment.