Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved [bug]: Signup form password issue #763 #765

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 43 additions & 31 deletions Html-files/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -387,36 +387,7 @@ <h1 style="color: hsl(203, 30%,26%);font-family: var(--ff-philosopher);">LOGIN</

animateCircles();

// Form submission event listener
document.getElementById('loginForm').addEventListener('submit', function(event) {
// Prevent form submission
event.preventDefault();

// Get the input values
const emailInput = document.getElementById('email').value;
const passwordInput = document.getElementById('password').value;

// Regular expression for email validation (simple check)
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

// Password validation (at least 8 characters)
const isValidPassword = passwordInput.length >= 8;

// Clear previous error message
document.getElementById('error-message').textContent = '';

// Validate the email and password separately
if (!emailPattern.test(emailInput)) {
// Display an error message if the email format is incorrect
document.getElementById('error-message').textContent = 'Invalid email format.';
} else if (!isValidPassword) {
// Display an error message if the password is too short
document.getElementById('error-message').textContent = 'Password must be at least 8 characters.';
} else {
// If both are valid, redirect to logged.html
window.location.assign('logged.html');
}
});


// Toggle password visibility
function togglePasswordVisibility() {
Expand All @@ -433,6 +404,47 @@ <h1 style="color: hsl(203, 30%,26%);font-family: var(--ff-philosopher);">LOGIN</
}
}
</script>
<!-- Add this element to display success messages -->
<div id="success-message" style="color: green;"></div>

<script>
// Form submission event listener
document.getElementById('loginForm').addEventListener('submit', function(event) {
// Prevent form submission
event.preventDefault();

// Get the input values
const emailInput = document.getElementById('email').value;
const passwordInput = document.getElementById('password').value;

// Regular expression for email validation (simple check)
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

// Password validation (at least 8 characters)
const isValidPassword = passwordInput.length >= 8;

// Clear previous error message
document.getElementById('error-message').textContent = '';
document.getElementById('success-message').textContent = '';

// Validate the email and password separately
if (!emailPattern.test(emailInput)) {
// Display an error message if the email format is incorrect
document.getElementById('error-message').textContent = 'Invalid email format.';
} else if (!isValidPassword) {
// Display an error message if the password is too short
document.getElementById('error-message').textContent = 'Password must be at least 8 characters.';
} else {
// If both are valid, display success message
document.getElementById('success-message').textContent = 'Login successful!';
// Optionally, redirect after a delay
setTimeout(() => {
window.location.assign('logged.html');
}, 2000); // Redirect after 2 seconds
}
});

</script>
<script>
window.embeddedChatbotConfig = {
chatbotId: "dGlQ5bP-F7GodLWzgrVAx",
Expand All @@ -451,4 +463,4 @@ <h1 style="color: hsl(203, 30%,26%);font-family: var(--ff-philosopher);">LOGIN</
<script>window.gtranslateSettings = {"default_language":"en","detect_browser_language":true,"wrapper_selector":".gtranslate_wrapper"}</script>
<script src="https://cdn.gtranslate.net/widgets/latest/float.js" defer></script>
</body>
</html>
</html>
47 changes: 38 additions & 9 deletions Html-files/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -346,18 +346,47 @@ <h1 style="font-family: var(--ff-philosopher);color: hsl(203, 30%, 26%);">SIGN U
defer>
</script>
<script>
// JavaScript to toggle password visibility
const passwordField = document.getElementById('password');
const showPasswordCheckbox = document.getElementById('showPassword');

showPasswordCheckbox.addEventListener('change', () => {
// JavaScript to toggle password visibility
const passwordField = document.getElementById('password');
const showPasswordCheckbox = document.getElementById('showPassword');
const passwordMessage = document.getElementById('passwordMessage');

showPasswordCheckbox.addEventListener('change', () => {
if (showPasswordCheckbox.checked) {
passwordField.type = 'text'; // Show password
passwordField.type = 'text'; // Show password
} else {
passwordField.type = 'password'; // Hide password
passwordField.type = 'password'; // Hide password
}
});
</script>
});

// Function to validate password constraints
function validatePassword() {
const password = passwordField.value;
const minLength = 8;
const hasNumber = /\d/;
const hasSpecialChar = /[!@#$%^&*(),.?":{}|<>]/;

let message = '';

if (password.length < minLength) {
message += `Password must be at least ${minLength} characters long. `;
}
if (!hasNumber.test(password)) {
message += 'Password must contain at least one number. ';
}
if (!hasSpecialChar.test(password)) {
message += 'Password must contain at least one special character. ';
}

passwordMessage.textContent = message;
}

// Add event listener to password field
passwordField.addEventListener('input', validatePassword);
</script>

<!-- Add this element to display password validation messages -->
<div id="passwordMessage" style="color: red;"></div>
<div class="gtranslate_wrapper"></div>
<script>window.gtranslateSettings = {"default_language":"en","detect_browser_language":true,"wrapper_selector":".gtranslate_wrapper"}</script>
<script src="https://cdn.gtranslate.net/widgets/latest/float.js" defer></script>
Expand Down