Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
seguinleo committed Aug 20, 2024
1 parent 79e0399 commit ae8d159
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/assets/css/style.min.css

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions src/assets/js/cloud/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ document.querySelector('#add-note').addEventListener('submit', async () => {

if (hidden === 1 && link !== null) return;

if (!title || title.length > 30 || folder.length > 30 || content.length > defaultScript.maxNoteContent || !color) return;
if (!title || title.length > 30 || folder.length > 18 || content.length > defaultScript.maxNoteContent || !color) return;
if (isUpdate && !noteId) return;
if (!/^[0-9]+$/.test(category)) return;

Expand Down Expand Up @@ -727,15 +727,27 @@ document.querySelector('#change-psswd').addEventListener('submit', async () => {
const a = document.querySelector('#old-psswd').value;
const e = document.querySelector('#new-psswd').value;
const t = document.querySelector('#new-psswd-valid').value;
if (!a || !e || !t || e.length < 8 || e.length > 64) return;
if (/^[0-9]+$/.test(e)) {
if (!a || !e || !t || e.length < 10 || e.length > 64) return;
if (/^[0-9]+$/.test(t)) {
defaultScript.showError('Password too weak (only numbers)...');
return;
}
if (/^[a-zA-Z]+$/.test(e)) {
if (/^[a-z]+$/.test(t)) {
defaultScript.showError('Password too weak (only lowercase letters)...');
return;
}
if (/^[A-Z]+$/.test(t)) {
defaultScript.showError('Password too weak (only uppercase letters)...');
return;
}
if (/^[a-zA-Z]+$/.test(t)) {
defaultScript.showError('Password too weak (only letters)...');
return;
}
if (/^[a-zA-Z0-9]+$/.test(t)) {
defaultScript.showError('Password should contain one special character...');
return;
}
if (e !== t) {
defaultScript.showError('Passwords do not match...');
return;
Expand Down
13 changes: 10 additions & 3 deletions src/assets/js/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ export function generateRandomBytes(length) {
}

export function getPassword(length) {
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&~"#\'(-_)=^$€*!?,.;:/|\\@%+{}[]<>`';
const lowercase = 'abcdefghijklmnopqrstuvwxyz';
const uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const digits = '0123456789';
const specialChars = '&~"#\'(-_)=^$€*!?,.;:/|\\@%+{}[]<>`';
const allChars = lowercase + uppercase + digits + specialChars;
let password = '';
const array = new Uint32Array(length);
window.crypto.getRandomValues(array);
for (let i = 0; i < length; i += 1) password += chars[parseInt(array[i] % chars.length, 10)];
for (let i = 0; i < length; i += 1) {
const randomIndex = parseInt(array[i] % allChars.length, 10);
password += allChars[randomIndex];
}
document.querySelector('#psswd-gen').textContent = password;
}

Expand Down Expand Up @@ -365,7 +372,7 @@ document.querySelector('#btn-filter').addEventListener('click', () => {
document.querySelector('#folder-popup-box button').addEventListener('click', async () => {
const folderName = document.querySelector('#name-folder').value.trim();
const select = document.querySelector('#folders');
if (folderName === '') return;
if (folderName === '' || folderName.length > 18) return;
const option = document.createElement('option');
option.value = folderName;
option.textContent = folderName;
Expand Down
22 changes: 15 additions & 7 deletions src/assets/js/local/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function changeLanguage(language) {
document.querySelector('#psswd-create').setAttribute('placeholder', 'Mot de passe');
document.querySelector('#psswd-create-valid').setAttribute('placeholder', 'Confirmer le mot de passe');
document.querySelector('#create-infos').textContent = 'Votre mot de passe est stocké en toute sécurité et vos notes chiffrées. Il vous sera impossible de récupérer votre mot de passe si vous l\'oubliez.';
document.querySelector('#gen-psswd summary').textContent = 'Générer un mot de passe';
document.querySelector('#create-form button[type="submit"]').textContent = 'Créer mon compte';
} else if (language === 'de') {
document.documentElement.setAttribute('lang', 'de');
Expand Down Expand Up @@ -114,7 +113,6 @@ function changeLanguage(language) {
document.querySelector('#psswd-create').setAttribute('placeholder', 'Passwort');
document.querySelector('#psswd-create-valid').setAttribute('placeholder', 'Passwort bestätigen');
document.querySelector('#create-infos').textContent = 'Ihr Passwort wird sicher gespeichert und Ihre Notizen verschlüsselt. Sie können Ihr Passwort nicht wiederherstellen, wenn Sie es vergessen.';
document.querySelector('#gen-psswd summary').textContent = 'Passwort generieren';
document.querySelector('#create-form button[type="submit"]').textContent = 'Mein Konto erstellen';
} else if (language === 'es') {
document.documentElement.setAttribute('lang', 'es');
Expand Down Expand Up @@ -168,7 +166,6 @@ function changeLanguage(language) {
document.querySelector('#psswd-create').setAttribute('placeholder', 'Contraseña');
document.querySelector('#psswd-create-valid').setAttribute('placeholder', 'Confirmar contraseña');
document.querySelector('#create-infos').textContent = 'Su contraseña se almacena de forma segura y sus notas cifradas. No podrá recuperar su contraseña si la olvida.';
document.querySelector('#gen-psswd summary').textContent = 'Generar una contraseña';
document.querySelector('#create-form button[type="submit"]').textContent = 'Crear mi cuenta';
} else {
document.documentElement.setAttribute('lang', 'en');
Expand Down Expand Up @@ -222,7 +219,6 @@ function changeLanguage(language) {
document.querySelector('#psswd-create').setAttribute('placeholder', 'Password');
document.querySelector('#psswd-create-valid').setAttribute('placeholder', 'Confirm password');
document.querySelector('#create-infos').textContent = 'Your password is stored securely and your notes encrypted. You will not be able to recover your password if you forget it.';
document.querySelector('#gen-psswd summary').textContent = 'Generate a password';
document.querySelector('#create-form button[type="submit"]').textContent = 'Create my account';
}
}
Expand Down Expand Up @@ -622,7 +618,7 @@ document.querySelector('#create-form').addEventListener('submit', async () => {
const e = document.querySelector('#name-create').value.trim();
const t = document.querySelector('#psswd-create').value;
const o = document.querySelector('#psswd-create-valid').value;
if (!e || !t || !o || e.length < 4 || e.length > 25 || t.length < 8 || t.length > 64) return;
if (!e || !t || !o || e.length < 3 || e.length > 30 || t.length < 10 || t.length > 64) return;
if (!/^[a-zA-ZÀ-ÿ -]+$/.test(e)) {
defaultScript.showError('Name can only contain letters, spaces and accents...');
return;
Expand All @@ -631,10 +627,22 @@ document.querySelector('#create-form').addEventListener('submit', async () => {
defaultScript.showError('Password too weak (only numbers)...');
return;
}
if (/^[a-z]+$/.test(t)) {
defaultScript.showError('Password too weak (only lowercase letters)...');
return;
}
if (/^[A-Z]+$/.test(t)) {
defaultScript.showError('Password too weak (only uppercase letters)...');
return;
}
if (/^[a-zA-Z]+$/.test(t)) {
defaultScript.showError('Password too weak (only letters)...');
return;
}
if (/^[a-zA-Z0-9]+$/.test(t)) {
defaultScript.showError('Password should contain one special character...');
return;
}
if (t !== o) {
defaultScript.showError('Passwords do not match...');
return;
Expand Down Expand Up @@ -678,7 +686,7 @@ document.querySelector('#connect-form').addEventListener('submit', async () => {
if (defaultScript.isLocked) return;
const e = document.querySelector('#name-connect').value.trim();
const t = document.querySelector('#psswd-connect').value;
if (!e || !t || e.length > 25 || t.length > 64 || !/^[a-zA-ZÀ-ÿ -]+$/.test(e)) return;
if (!e || !t || e.length > 30 || t.length > 64) return;
const nameConnect = e;
const psswdConnect = t;
try {
Expand Down Expand Up @@ -728,7 +736,7 @@ document.querySelector('#add-note').addEventListener('submit', async () => {
const category = parseInt(document.querySelector('input[name="category"]:checked').value, 10);
const folder = document.querySelector('#note-popup-box #folders').value;

if (!title || title.length > 30 || folder.length > 30 || content.length > defaultScript.maxNoteContent || !color || !/^[0-9]+$/.test(category)) return;
if (!title || title.length > 30 || folder.length > 18 || content.length > defaultScript.maxNoteContent || !color || !/^[0-9]+$/.test(category)) return;

const mdContent = DOMPurify.sanitize(content, {
SANITIZE_NAMED_PROPS: true,
Expand Down
2 changes: 1 addition & 1 deletion src/assets/php/connectUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
throw new Exception('Connection failed');
return;
}
if (strlen($nameConnect) < 4 || strlen($nameConnect) > 25 || strlen($psswdConnect) < 8 || strlen($psswdConnect) > 64) {
if (strlen($nameConnect) < 3 || strlen($nameConnect) > 30 || strlen($psswdConnect) < 10 || strlen($psswdConnect) > 64) {
throw new Exception('Account creation failed');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/php/createUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
throw new Exception('Account creation failed');
return;
}
if (strlen($nameCreate) < 4 || strlen($nameCreate) > 25 || strlen($psswdCreate) < 8 || strlen($psswdCreate) > 64) {
if (strlen($nameCreate) < 3 || strlen($nameCreate) > 30 || strlen($psswdCreate) < 10 || strlen($psswdCreate) > 64) {
throw new Exception('Account creation failed');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/php/deleteAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
throw new Exception('Account deletion failed');
return;
}
if (strlen($psswd) < 8 || strlen($psswd) > 64) {
if (strlen($psswd) < 10 || strlen($psswd) > 64) {
throw new Exception('Account deletion failed');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/php/updatePsswd.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
throw new Exception('Password update failed');
return;
}
if (strlen($psswdNew) < 8 || strlen($psswdNew) > 64) {
if (strlen($psswdNew) < 10 || strlen($psswdNew) > 64) {
throw new Exception('Password update failed');
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/assets/sass/style.sass
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ dialog
font-size: .9rem

.content
width: 90vw
max-width: 1500px
width: 80vw
max-width: 1300px

input,
textarea
Expand Down
47 changes: 22 additions & 25 deletions src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<link rel="apple-touch-icon" href="./assets/icons/apple-touch-icon.png">
<link rel="icon" href="./favicon.ico">
<link rel="stylesheet" href="./assets/css/style.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
<link rel="manifest" href="./app.webmanifest">
</head>
<body class="accent1">
Expand Down Expand Up @@ -222,7 +222,7 @@
<div class="error-notification d-none"></div>
</div>
<div class="row">
<input type="text" id="name-folder" maxlength="30" aria-label="Name" required>
<input type="text" id="name-folder" maxlength="18" aria-label="Name" required>
</div>
<button type="submit"></button>
</form>
Expand Down Expand Up @@ -442,13 +442,13 @@
<div class="error-notification d-none"></div>
</div>
<div class="row">
<input id="old-psswd" type="password" minlength="8" maxlength="64" aria-label="Old password" required>
<input id="old-psswd" type="password" minlength="10" maxlength="64" aria-label="Old password" required>
</div>
<div class="row">
<input id="new-psswd" type="password" minlength="8" maxlength="64" aria-label="New password" required>
<input id="new-psswd" type="password" minlength="10" maxlength="64" aria-label="New password" required>
</div>
<div class="row">
<input id="new-psswd-valid" type="password" minlength="8" maxlength="64" aria-label="Confirm new password" required>
<input id="new-psswd-valid" type="password" minlength="10" maxlength="64" aria-label="Confirm new password" required>
</div>
<div class="row d-flex">
<p id="psswd-gen"></p>
Expand All @@ -469,7 +469,7 @@
<div class="error-notification d-none"></div>
</div>
<div class="row">
<input id="delete-psswd" type="password" minlength="8" maxlength="64" aria-label="Password" required>
<input id="delete-psswd" type="password" minlength="10" maxlength="64" aria-label="Password" required>
</div>
<button type="submit"></button>
</form>
Expand Down Expand Up @@ -547,16 +547,16 @@
<input
id="name-connect"
type="text"
minlength="4"
maxlength="25"
minlength="3"
maxlength="30"
spellcheck="false"
autocapitalize="off"
aria-label="Name"
required
>
</div>
<div class="row">
<input id="psswd-connect" type="password" minlength="8" maxlength="64" aria-label="Password" required>
<input id="psswd-connect" type="password" minlength="10" maxlength="64" aria-label="Password" required>
</div>
<button type="submit"></button>
</form>
Expand All @@ -577,36 +577,33 @@
<input
id="name-create"
type="text"
minlength="4"
maxlength="25"
minlength="3"
maxlength="30"
spellcheck="false"
autocapitalize="off"
aria-label="Name"
required
>
</div>
<div class="row">
<input id="psswd-create" type="password" minlength="8" maxlength="64" aria-label="Password" required>
<input id="psswd-create" type="password" minlength="10" maxlength="64" aria-label="Password" required>
</div>
<div class="row">
<input id="psswd-create-valid" type="password" minlength="8" maxlength="64" aria-label="Confirm password" required>
<input id="psswd-create-valid" type="password" minlength="10" maxlength="64" aria-label="Confirm password" required>
</div>
<div class="row d-flex">
<p id="psswd-gen"></p>
<button type="button" id="copy-password-btn" aria-label="Copy password">
<i class="fa-solid fa-clipboard"></i>
</button>
<button type="button" id="submit-gen-psswd" aria-label="Generate password">
<i class="fa-solid fa-arrow-rotate-right"></i>
</button>
</div>
<div class="row">
<i class="fa-solid fa-circle-info" role="none"></i>
<span id="create-infos"></span>
</div>
<details id="gen-psswd">
<summary></summary>
<div class="row d-flex">
<p id="psswd-gen"></p>
<button type="button" id="copy-password-btn" aria-label="Copy password">
<i class="fa-solid fa-clipboard"></i>
</button>
<button type="button" id="submit-gen-psswd" aria-label="Generate password">
<i class="fa-solid fa-arrow-rotate-right"></i>
</button>
</div>
</details>
<button type="submit"></button>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/share/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; connect-src 'self'; font-src 'self' https://cdnjs.cloudflare.com/; form-action 'self'; img-src http:; manifest-src 'self'; script-src 'self'; script-src-attr 'none'; style-src 'self' https://cdnjs.cloudflare.com/; style-src-attr 'none'; worker-src 'self'">
<link rel="icon" href="../favicon.ico">
<link rel="stylesheet" href="./assets/css/style.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
</head>
<body>
<main></main>
Expand Down

0 comments on commit ae8d159

Please sign in to comment.