Skip to content

Commit d14ec04

Browse files
committed
update login and register page
Added Remenber Me check box, Added email Added email validation to ensure that the user enters a valid email address. Added password strength check to require passwords to contain at least 8 characters, one uppercase letter, and one number. Added password confirmation to ensure that the password entered by the user is the same twice.
1 parent e80eb47 commit d14ec04

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

code/frontend/package-lock.json

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

code/frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"axios": "^1.9.0",
2121
"react": "^19.1.0",
2222
"react-dom": "^19.1.0",
23-
"react-router-dom": "^6.30.0"
23+
"react-router-dom": "^6.30.0",
24+
"validator": "^13.15.0"
2425
},
2526
"devDependencies": {
2627
"@testing-library/jest-dom": "^6.6.3",

code/frontend/src/pages/Login.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
const Login = () => {
1515
const [username, setUsername] = useState('');
1616
const [password, setPassword] = useState('');
17+
const [rememberMe, setRememberMe] = useState(false);
1718
const [error, setError] = useState('');
1819
const [loading, setLoading] = useState(false);
1920
const navigate = useNavigate();
@@ -26,7 +27,7 @@ const Login = () => {
2627
setLoading(true);
2728

2829
try {
29-
const { success, error: loginError } = await login(username, password);
30+
const { success, error: loginError } = await login(username, password, rememberMe);
3031
if (success) {
3132
const from = location.state?.from?.pathname || '/home';
3233
navigate(from, { replace: true });
@@ -79,6 +80,16 @@ const Login = () => {
7980
onChange={(e) => setPassword(e.target.value)}
8081
disabled={loading}
8182
/>
83+
<Box sx={{ display: 'flex', alignItems: 'center', mt: 1 }}>
84+
<input
85+
type="checkbox"
86+
id="rememberMe"
87+
checked={rememberMe}
88+
onChange={(e) => setRememberMe(e.target.checked)}
89+
disabled={loading}
90+
/>
91+
<label htmlFor="rememberMe" style={{ marginLeft: '8px' }}>Remember me</label>
92+
</Box>
8293
<Button
8394
type="submit"
8495
fullWidth

code/frontend/src/pages/Register.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useState } from 'react';
22
import { useNavigate } from 'react-router-dom';
33
import { useAuth } from '../contexts/AuthContext';
4+
import validator from 'validator';
45
import {
56
Container,
67
Paper,
@@ -26,6 +27,18 @@ const Register = () => {
2627
setError('');
2728
setLoading(true);
2829

30+
if (!validator.isEmail(email)) {
31+
setError('Invalid email address');
32+
setLoading(false);
33+
return;
34+
}
35+
36+
if (password.length < 8 || !/[A-Z]/.test(password) || !/[0-9]/.test(password)) {
37+
setError('Password must be at least 8 characters long, contain an uppercase letter, and a number');
38+
setLoading(false);
39+
return;
40+
}
41+
2942
if (password !== confirmPassword) {
3043
setError('Passwords do not match');
3144
setLoading(false);

0 commit comments

Comments
 (0)