Merge pull request #314 from appwrite/feat-user-password-history-and-dictionary

update password history and password dictionary
This commit is contained in:
Torsten Dittmann authored and GitHub committed 2023-03-29 15:02:49 +02:00
commit 0de202d7fa
4 files changed
+144

No files matched your search

+2
View File
@@ -141,6 +141,8 @@ export enum Submit {
TeamUpdateName = 'submit_team_update_name',
AuthLimitUpdate = 'submit_auth_limit_update',
AuthStatusUpdate = 'submit_auth_status_update',
AuthPasswordHistoryUpdate = 'submit_auth_password_history_limit_update',
AuthPasswordDictionaryUpdate = 'submit_auth_password_dictionary_update',
SessionsLengthUpdate = 'submit_sessions_length_update',
SessionsLimitUpdate = 'submit_sessions_limit_update',
SessionDelete = 'submit_session_delete',
@@ -1,5 +1,7 @@
<script lang="ts">
import { Container } from '$lib/layout';
import UpdatePasswordDictionary from './updatePasswordDictionary.svelte';
import UpdatePasswordHistory from './updatePasswordHistory.svelte';
import UpdateSessionLength from './updateSessionLength.svelte';
import UpdateSessionsLimit from './updateSessionsLimit.svelte';
import UpdateUsersLimit from './updateUsersLimit.svelte';
@@ -9,4 +11,6 @@
<UpdateUsersLimit />
<UpdateSessionLength />
<UpdateSessionsLimit />
<UpdatePasswordHistory />
<UpdatePasswordDictionary />
</Container>
@@ -0,0 +1,62 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { CardGrid, Heading } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { Button, Form, FormList, InputSwitch } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { project } from '../../store';
const projectId = $project.$id;
let passwordDictionary = $project.authPasswordDictionary ?? false;
async function updatePasswordDictionary() {
try {
await sdk.forConsole.projects.updateAuthPasswordDictionary(
projectId,
passwordDictionary
);
await invalidate(Dependencies.PROJECT);
addNotification({
type: 'success',
message: 'Updated password dictionary check.'
});
trackEvent(Submit.AuthPasswordDictionaryUpdate);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.AuthPasswordDictionaryUpdate);
}
}
</script>
<Form onSubmit={updatePasswordDictionary}>
<CardGrid>
<Heading tag="h2" size="6">Password Dictionary</Heading>
<svelte:fragment slot="aside">
<FormList>
<InputSwitch
bind:value={passwordDictionary}
id="passwordDictionary"
label="Password Dictionary" />
</FormList>
<p class="text">
Enabling this option prevent users from setting insecure passwords by comparing the
user's password with the <a
target="_blank"
rel="noopener noreferrer"
class="link"
href="https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10k-most-common.txt"
>10k most commonly used passwords.</a>
</p>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button disabled={passwordDictionary === $project.authPasswordDictionary} submit
>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>
@@ -0,0 +1,76 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { CardGrid, Heading } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { Button, Form, InputNumber, InputSwitch } from '$lib/elements/forms';
import FormList from '$lib/elements/forms/formList.svelte';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { project } from '../../store';
const projectId = $project.$id;
let passwordHistory = $project.authPasswordHistory < 1 ? 5 : $project.authPasswordHistory;
let passwordHistoryEnabled = ($project.authPasswordHistory ?? 0) != 0;
let initialPasswordHistoryEnabled = passwordHistoryEnabled;
async function updatePasswordHistoryLimit() {
try {
await sdk.forConsole.projects.updateAuthPasswordHistory(
projectId,
passwordHistoryEnabled ? passwordHistory : 0
);
await invalidate(Dependencies.PROJECT);
initialPasswordHistoryEnabled = passwordHistoryEnabled;
addNotification({
type: 'success',
message: 'Updated password history limit.'
});
trackEvent(Submit.AuthPasswordHistoryUpdate);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.AuthPasswordHistoryUpdate);
}
}
</script>
<Form onSubmit={updatePasswordHistoryLimit}>
<CardGrid>
<Heading tag="h2" size="6">Password History</Heading>
<svelte:fragment slot="aside">
<FormList>
<InputSwitch
bind:value={passwordHistoryEnabled}
id="passwordHisotryEnabled"
label="Password History" />
</FormList>
<p class="text">
Enabling this option prevents users from reusing recent passwords by comparing the
new password with their password history.
</p>
<p class="text">
Set the maximum number of passwords saved per user. Maximum 20 passwords.
</p>
<FormList>
<InputNumber
max={20}
min={1}
id="max-session"
label="Limit"
disabled={!passwordHistoryEnabled}
bind:value={passwordHistory} />
</FormList>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button
disabled={(passwordHistory === $project.authPasswordHistory ||
$project.authPasswordHistory === 0) &&
initialPasswordHistoryEnabled === passwordHistoryEnabled}
submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>