Skip to content

Commit

Permalink
Improve email validation
Browse files Browse the repository at this point in the history
  • Loading branch information
zigazajc007 committed Nov 5, 2024
1 parent 54c2ece commit 10882e6
Show file tree
Hide file tree
Showing 9 changed files with 1,004 additions and 1,006 deletions.
1,939 changes: 970 additions & 969 deletions package-lock.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "passky-server",
"description": "Server for Passky (password manager)",
"version": "8.1.7",
"main": "tailwind.config.js",
"scripts": {
"build": "npx tailwindcss -i ./tailwind.css -o ./server/src/website/css/tailwind.min.css --minify"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Rabbit-Company/Passky-Server.git"
},
"author": "Rabbit Company",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/Rabbit-Company/Passky-Server/issues"
},
"homepage": "https://github.com/Rabbit-Company/Passky-Server#readme",
"devDependencies": {
"tailwindcss": "^3.4.3"
}
}
"name": "passky-server",
"description": "Server for Passky (password manager)",
"version": "8.1.8",
"main": "tailwind.config.js",
"scripts": {
"build": "npx tailwindcss -i ./tailwind.css -o ./server/src/website/css/tailwind.min.css --minify"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Rabbit-Company/Passky-Server.git"
},
"author": "Rabbit Company",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/Rabbit-Company/Passky-Server/issues"
},
"homepage": "https://github.com/Rabbit-Company/Passky-Server#readme",
"devDependencies": {
"tailwindcss": "^3.4.14"
}
}
11 changes: 5 additions & 6 deletions server/src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,8 @@ public static function createAccount(string $username, string $password, string
if($amount_of_accounts >= Settings::getMaxAccounts()) return Display::json(15);
}

$sub_email = filter_var($email, FILTER_SANITIZE_EMAIL);

if(!preg_match("/^[a-z0-9._]{6,30}$/i", $username)) return Display::json(12);
if(!filter_var($sub_email, FILTER_VALIDATE_EMAIL)) return Display::json(6);
if(!preg_match("/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,}$/i", $email) || strlen($email) > 200) return Display::json(6);
if(!preg_match("/^[a-z0-9]{128}$/i", $password)) return Display::json(5);

$username = strtolower($username);
Expand Down Expand Up @@ -923,14 +921,15 @@ public static function removeYubiKey(string $username, string $token, string $id

public static function forgotUsername(string $email) : string{
if(!Settings::getMail()) return Display::json(28);
$sub_email = filter_var($email, FILTER_SANITIZE_EMAIL);
if(!filter_var($sub_email, FILTER_VALIDATE_EMAIL)) return Display::json(6);
if(!preg_match("/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,}$/i", $email) || strlen($email) > 200) return Display::json(6);

$email = strtolower($email);

try{
$conn = Settings::createConnection();

$stmt = $conn->prepare('SELECT username FROM users WHERE email = :email');
$stmt->bindParam(':email', $sub_email, PDO::PARAM_STR);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->execute();

$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
Expand Down
2 changes: 1 addition & 1 deletion server/src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Settings{
*/

public static function getVersion() : string{
return '8.1.7';
return '8.1.8';
}

public static function getLocation() : string{
Expand Down
2 changes: 1 addition & 1 deletion server/src/website/actions/createLicense.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

session_start();

$token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING);
$token = htmlspecialchars(filter_input(INPUT_GET, 'token'), ENT_QUOTES, 'UTF-8');

if(!isset($_SESSION['username']) || !isset($_SESSION['token']) || !$token || $token !== $_SESSION['token']){
$_SESSION['page'] = 'home';
Expand Down
2 changes: 1 addition & 1 deletion server/src/website/actions/deleteAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

session_start();

$token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING);
$token = htmlspecialchars(filter_input(INPUT_GET, 'token'), ENT_QUOTES, 'UTF-8');

if(!isset($_SESSION['username']) || !isset($_SESSION['token']) || !$token || $token !== $_SESSION['token']){
$_SESSION['page'] = 'home';
Expand Down
2 changes: 1 addition & 1 deletion server/src/website/actions/deleteLicense.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

session_start();

$token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING);
$token = htmlspecialchars(filter_input(INPUT_GET, 'token'), ENT_QUOTES, 'UTF-8');

if(!isset($_SESSION['username']) || !isset($_SESSION['token']) || !$token || $token !== $_SESSION['token']){
$_SESSION['page'] = 'home';
Expand Down
8 changes: 3 additions & 5 deletions server/src/website/actions/editAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

session_start();

$token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING);
$token = htmlspecialchars(filter_input(INPUT_GET, 'token'), ENT_QUOTES, 'UTF-8');

if(!isset($_SESSION['username']) || !isset($_SESSION['token']) || !$token || $token !== $_SESSION['token']){
$_SESSION['page'] = 'home';
Expand All @@ -17,8 +17,6 @@
$disable2fa = ($_GET['disable2fa'] === 'true') ? true : false;
$disablePremium = ($_GET['disablePremium'] === 'true') ? true : false;

$sub_email = filter_var($email, FILTER_SANITIZE_EMAIL);

if(!is_numeric($maxPasswords)) $maxPasswords = Settings::getMaxPasswords();
if($maxPasswords < 0) $maxPasswords = -1;
if($maxPasswords > 1_000_000_000) $maxPasswords = 1_000_000_000;
Expand All @@ -28,10 +26,10 @@
try{
$conn = Settings::createConnection();

if(filter_var($sub_email, FILTER_VALIDATE_EMAIL)){
if(preg_match("/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,}$/i", $email) && strlen($email) <= 200){
$stmt = $conn->prepare('UPDATE users SET email = :email, max_passwords = :maxPasswords WHERE username = :username');
$stmt->bindParam(':username', $username, PDO::PARAM_STR);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':email', strtolower($email), PDO::PARAM_STR);
$stmt->bindParam(':maxPasswords', $maxPasswords, PDO::PARAM_INT);
$stmt->execute();
}else{
Expand Down
2 changes: 1 addition & 1 deletion server/src/website/css/tailwind.min.css

Large diffs are not rendered by default.

0 comments on commit 10882e6

Please sign in to comment.