Implemented password strength test feature/106-password_strength #115
@ -14,6 +14,7 @@
|
||||
"license": "CC-BY-NC-SA-4.0",
|
||||
"dependencies": {
|
||||
"@odit/lfk-client-js": "0.7.0",
|
||||
"check-password-strength": "^2.0.2",
|
||||
"csvtojson": "^2.0.10",
|
||||
"gridjs": "3.3.0",
|
||||
"localforage": "1.9.0",
|
||||
|
52
src/components/auth/PasswordStrength.svelte
Normal file
52
src/components/auth/PasswordStrength.svelte
Normal file
@ -0,0 +1,52 @@
|
||||
<script context="module">
|
||||
import { passwordStrength } from "check-password-strength";
|
||||
export function password_strong_enough(password_change) {
|
||||
let strength = passwordStrength(password_change);
|
||||
return (
|
||||
strength?.contains.includes("lowercase") &&
|
||||
strength?.contains.includes("uppercase") &&
|
||||
strength?.contains.includes("number") &&
|
||||
strength?.length > 9
|
||||
);
|
||||
}
|
||||
export function password_strong_enough_and_equal(
|
||||
password_change,
|
||||
password_confirm
|
||||
) {
|
||||
return (
|
||||
password_strong_enough(password_change) &&
|
||||
password_change === password_confirm
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import { getLocaleFromNavigator, _ } from "svelte-i18n";
|
||||
import { passwordStrength as Strength } from "check-password-strength";
|
||||
export let password_change;
|
||||
export let password_confirm;
|
||||
|
||||
$: strength = Strength(password_change);
|
||||
$: passwords_match =
|
||||
!password_confirm || password_confirm === password_change;
|
||||
</script>
|
||||
|
||||
<div class="ml-4">
|
||||
<ul class="list-disc font-medium tracking-wide text-red-500 text-xs">
|
||||
{#if !strength.contains.includes('lowercase')}
|
||||
<li>{$_('must-contain-a-lowercase-letter')}</li>
|
||||
{/if}
|
||||
{#if !strength.contains.includes('uppercase')}
|
||||
<li>{$_('must-contain-a-uppercase-letter')}</li>
|
||||
{/if}
|
||||
{#if !strength.contains.includes('number')}
|
||||
<li>{$_('must-contain-a-number')}</li>
|
||||
{/if}
|
||||
{#if !(strength.length > 9)}
|
||||
<li>{$_('must-be-at-least-10-characters-long')}</li>
|
||||
{/if}
|
||||
{#if !(passwords_match == true)}
|
||||
<li>{$_('passwords-dont-match')}</li>
|
||||
{/if}
|
||||
</ul>
|
||||
</div>
|
@ -3,36 +3,41 @@
|
||||
import { _ } from "svelte-i18n";
|
||||
import Toastify from "toastify-js";
|
||||
import "toastify-js/src/toastify.css";
|
||||
import PasswordStrength, {
|
||||
password_strong_enough,
|
||||
} from "../auth/PasswordStrength.svelte";
|
||||
let state = "reset_in_progress";
|
||||
let password = "";
|
||||
export let params;
|
||||
function set_new_password() {
|
||||
if(password.trim() !== ""){
|
||||
if (password.trim() !== "") {
|
||||
Toastify({
|
||||
text: $_('password-reset-in-progress'),
|
||||
text: $_("password-reset-in-progress"),
|
||||
duration: 3500,
|
||||
}).showToast();
|
||||
AuthService.authControllerResetPassword(atob(params.resetkey),{ password })
|
||||
AuthService.authControllerResetPassword(atob(params.resetkey), {
|
||||
password,
|
||||
})
|
||||
.then((resp) => {
|
||||
Toastify({
|
||||
text: $_('password-reset-successful'),
|
||||
text: $_("password-reset-successful"),
|
||||
duration: 3500,
|
||||
}).showToast();
|
||||
state="reset_success";
|
||||
state = "reset_success";
|
||||
})
|
||||
.catch((err) => {
|
||||
state="reset_error";
|
||||
state = "reset_error";
|
||||
});
|
||||
} else {
|
||||
Toastify({
|
||||
text: $_('please-provide-a-password'),
|
||||
text: $_("please-provide-a-password"),
|
||||
duration: 3500,
|
||||
}).showToast();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if state==="reset_success"}
|
||||
{#if state === 'reset_success'}
|
||||
<div class="min-h-screen flex items-center justify-center bg-gray-100">
|
||||
<div class="max-w-md w-full py-12 px-6">
|
||||
<img style="height:10rem;" class="mx-auto" src="/lfk-logo.png" alt="" />
|
||||
@ -56,8 +61,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{:else if state==="reset_error"}
|
||||
<div class="min-h-screen flex items-center justify-center bg-gray-100">
|
||||
{:else if state === 'reset_error'}
|
||||
<div class="min-h-screen flex items-center justify-center bg-gray-100">
|
||||
<div class="max-w-md w-full py-12 px-6">
|
||||
<img style="height:10rem;" class="mx-auto" src="/lfk-logo.png" alt="" />
|
||||
<p class="mt-6 text-lg text-center font-bold text-gray-900">
|
||||
@ -79,8 +84,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{:else if state==="reset_in_progress"}
|
||||
</div>
|
||||
{:else if state === 'reset_in_progress'}
|
||||
<div class="min-h-screen flex items-center justify-center bg-gray-100">
|
||||
<div class="max-w-md w-full py-12 px-6">
|
||||
<img style="height:10rem;" class="mx-auto" src="/lfk-logo.png" alt="" />
|
||||
@ -102,11 +107,14 @@
|
||||
placeholder={$_('new-password')}
|
||||
bind:value={password} />
|
||||
</div>
|
||||
<PasswordStrength bind:password_change={password} />
|
||||
</div>
|
||||
|
||||
<div class="mt-5">
|
||||
<button
|
||||
on:click={set_new_password}
|
||||
disabled={!password_strong_enough(password)}
|
||||
class:opacity-50={!password_strong_enough(password)}
|
||||
type="submit"
|
||||
class="relative block w-full py-2 px-3 border border-transparent rounded-md text-white font-semibold bg-gray-800 hover:bg-gray-700 focus:bg-gray-900 focus:outline-none focus:shadow-outline sm:text-sm">
|
||||
<span class="absolute left-0 inset-y pl-3">
|
||||
|
@ -1,6 +1,9 @@
|
||||
<script>
|
||||
import { getLocaleFromNavigator, _ } from "svelte-i18n";
|
||||
import { RunnerOrganizationService, RunnerTeamService } from "@odit/lfk-client-js";
|
||||
import {
|
||||
RunnerOrganizationService,
|
||||
RunnerTeamService,
|
||||
} from "@odit/lfk-client-js";
|
||||
import Toastify from "toastify-js";
|
||||
export let sponsoring_contracts_show = false;
|
||||
export let generate_runners = [];
|
||||
|
@ -4,6 +4,9 @@
|
||||
import { MeService } from "@odit/lfk-client-js";
|
||||
import Toastify from "toastify-js";
|
||||
import ConfirmProfileDeletion from "./ConfirmProfileDeletion.svelte";
|
||||
import PasswordStrength, {
|
||||
password_strong_enough_and_equal,
|
||||
} from "../auth/PasswordStrength.svelte";
|
||||
$: data_loaded = false;
|
||||
$: delete_triggered = false;
|
||||
$: original_data = {};
|
||||
@ -15,8 +18,10 @@
|
||||
JSON.stringify(editable) === JSON.stringify(original_data)
|
||||
);
|
||||
$: save_enabled = changes_performed && isEmail(editable.email);
|
||||
$: update_password_enabled =
|
||||
password_change.length > 0 && password_change === password_confirm;
|
||||
$: update_password_enabled = password_strong_enough_and_equal(
|
||||
password_change,
|
||||
password_confirm
|
||||
);
|
||||
const user_promise = MeService.meControllerGet().then((data) => {
|
||||
data_loaded = true;
|
||||
data.groups = data.groups.map((g) => g.id);
|
||||
@ -45,7 +50,7 @@
|
||||
function changePassword() {
|
||||
if (data_loaded === true && update_password_enabled) {
|
||||
Toastify({
|
||||
text: $_('changing-your-password'),
|
||||
text: $_("changing-your-password"),
|
||||
duration: 2500,
|
||||
}).showToast();
|
||||
let postdata = Object.assign({}, original_data);
|
||||
@ -56,7 +61,7 @@
|
||||
password_change = "";
|
||||
postdata = {};
|
||||
Toastify({
|
||||
text: $_('password-changed'),
|
||||
text: $_("password-changed"),
|
||||
duration: 2500,
|
||||
backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)",
|
||||
}).showToast();
|
||||
@ -242,10 +247,7 @@
|
||||
class="border-gray-300 placeholder-gray-500 appearance-none rounded-md relative block w-full px-3 py-2 border focus:outline-none focus:shadow-outline-blue focus:border-blue-300 focus:z-10 sm:text-sm"
|
||||
placeholder={$_('password')} />
|
||||
</div>
|
||||
{#if password_change != password_confirm && password_change.length > 0}
|
||||
<span
|
||||
class="flex items-center font-medium tracking-wide text-red-500 text-xs mt-1 ml-1">{$_('passwords-dont-match')}</span>
|
||||
{/if}
|
||||
<PasswordStrength bind:password_change bind:password_confirm />
|
||||
</div>
|
||||
<div class="px-4 py-3 bg-gray-50 text-right sm:px-6">
|
||||
<button
|
||||
|
@ -5,6 +5,9 @@
|
||||
import { UserService } from "@odit/lfk-client-js";
|
||||
import isEmail from "validator/es/lib/isEmail";
|
||||
import Toastify from "toastify-js";
|
||||
import PasswordStrength, {
|
||||
password_strong_enough,
|
||||
} from "../auth/PasswordStrength.svelte";
|
||||
export let modal_open;
|
||||
export let current_users;
|
||||
let firstname_input;
|
||||
@ -28,7 +31,10 @@
|
||||
$: isLastnameValid = lastname_input_value.trim().length !== 0;
|
||||
$: isFirstnameValid = firstname_input_value.trim().length !== 0;
|
||||
$: createbtnenabled =
|
||||
isFirstnameValid && isLastnameValid && isPasswordValid && isEmailValid;
|
||||
isFirstnameValid &&
|
||||
isLastnameValid &&
|
||||
password_strong_enough(password_input_value) &&
|
||||
isEmailValid;
|
||||
(function () {
|
||||
document.onkeydown = function (e) {
|
||||
e = e || window.event;
|
||||
@ -203,12 +209,8 @@
|
||||
type="password"
|
||||
name="password"
|
||||
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 rounded-md p-2" />
|
||||
{#if !isPasswordValid}
|
||||
<span
|
||||
class="flex items-center font-medium tracking-wide text-red-500 text-xs mt-1 ml-1">
|
||||
{$_('password-is-required')}
|
||||
</span>
|
||||
{/if}
|
||||
<PasswordStrength
|
||||
bind:password_change={password_input_value} />
|
||||
</div>
|
||||
<div class="col-span-6">
|
||||
<label
|
||||
|
@ -245,6 +245,10 @@
|
||||
"middle-name": "Mittelname",
|
||||
"minimum-lap-time-in-s": "Minimale Rundenzeit (in Sekunden)",
|
||||
"minimum-lap-time-must-be-a-positive-number-or-0": "Die minimale Rundenzeit muss eine positive Zahl oder 0 sein",
|
||||
"must-be-at-least-10-characters-long": "Passwort muss mindestens 10 Zeichen lang sein!",
|
||||
"must-contain-a-lowercase-letter": "Passwort muss einen Großbuchstaben enthalten!",
|
||||
"must-contain-a-number": "Passwort muss eine Zahl enthalten!",
|
||||
"must-contain-a-uppercase-letter": "Passwort muss einen Kleinbuchstaben enthalten!",
|
||||
"name": "Name",
|
||||
"name-is-required": "Der Gruppenname muss angegeben werden",
|
||||
"new-password": "Neues Passwort",
|
||||
@ -276,7 +280,7 @@
|
||||
"password-reset-in-progress": "Passwort wird zurückgesetzt...",
|
||||
"password-reset-mail-sent": "Passwort-Reset Mail wurde an \"{usersEmail}\" geschickt.",
|
||||
"password-reset-successful": "Passwort erfolgreich zurückgesetzt!",
|
||||
"passwords-dont-match": "Die Passwörter stimmen nicht überein.",
|
||||
"passwords-dont-match": "Die Passwörter stimmen nicht überein!",
|
||||
"pdf-generation-failed": "PDF Generierung fehlgeschlagen!",
|
||||
"pdf-successfully-generated": "PDF wurde erfolgreich generiert!",
|
||||
"pdfs-successfully-generated": "Alle PDFs wurden generiert!",
|
||||
|
@ -245,6 +245,10 @@
|
||||
"middle-name": "Middle name",
|
||||
"minimum-lap-time-in-s": "minimum lap time in s",
|
||||
"minimum-lap-time-must-be-a-positive-number-or-0": "minimum lap time must be a positive number or 0",
|
||||
"must-be-at-least-10-characters-long": "Must be at least 10 characters long!",
|
||||
"must-contain-a-lowercase-letter": "Must contain a lowercase letter!",
|
||||
"must-contain-a-number": "Must contain a number!",
|
||||
"must-contain-a-uppercase-letter": "Must contain a uppercase letter!",
|
||||
"name": "Name",
|
||||
"name-is-required": "Name is required",
|
||||
"new-password": "New password",
|
||||
@ -276,7 +280,7 @@
|
||||
"password-reset-in-progress": "Password Reset in Progress...",
|
||||
"password-reset-mail-sent": "Password reset mail was sent to \"{usersEmail}\".",
|
||||
"password-reset-successful": "Password Reset successful!",
|
||||
"passwords-dont-match": "Passwords don't match",
|
||||
"passwords-dont-match": "Passwords don't match!",
|
||||
"pdf-generation-failed": "PDF generation failed!",
|
||||
"pdf-successfully-generated": "PDF successfully generated!",
|
||||
"pdfs-successfully-generated": "PDFs successfully generated!",
|
||||
|
Loading…
x
Reference in New Issue
Block a user