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

#15 Requirement of Proper Input Handling in Login/Register form #29

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 27 additions & 1 deletion Html-files/scriptsignup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,33 @@ document.getElementById("signup-form").addEventListener("submit", function(event
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;

if (validateForm(name, email, password)) {
const nameError = document.getElementById("name-error");
const passwordError = document.getElementById("password-error");
const emailError = document.getElementById("email-error");

// Reset error messages
nameError.textContent = "";
passwordError.textContent = "";
emailError.textContent = "";

// Regex to prevent <, >, ", or / in the name and password
const spcharexp = /[<>"/]/;

let valid = true; // A flag to track validation status

// Name validation
if (spcharexp.test(name)) {
nameError.textContent = "Name cannot contain <, >, \", or /";
valid = false;
}

// Password validation
if (spcharexp.test(password)) {
passwordError.textContent = "Password cannot contain <, >, \", or /";
valid = false;
}

if (validateForm(name, email, password) && valid) {
// Simulate a successful registration (Replace with actual Firebase sign-up logic)
console.log("Form submitted with:", { name, email, password });
window.location.href = "../Html-files/signed.html";
Expand Down
46 changes: 42 additions & 4 deletions Html-files/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,38 @@
text-shadow: 0px 0px 2px rgb(90, 90, 90), 0px 0px 5px gray;
transform: translateZ(-40px);
}
.error-message {
color: red;
font-size: 0.9em;
}
.textfield {
margin-bottom: 15px;
}
/* Tooltip styling */
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 200px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 5px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%; /* Position above the input field */
left: 50%;
margin-left: -100px; /* Center the tooltip */
opacity: 0;
transition: opacity 0.3s;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
.area .way:nth-child(1):hover ~ .box{transform: rotateX(-20deg) rotateY(20deg);}
.area .way:nth-child(2):hover ~ .box{transform: rotateX(-20deg) rotateY(0deg);}
.area .way:nth-child(3):hover ~ .box{transform: rotateX(-20deg) rotateY(-20deg);}
Expand Down Expand Up @@ -186,15 +218,21 @@ <h1 style="font-family: var(--ff-philosopher);color: hsl(203, 30%, 26%);">SIGN U
<div class="textfield">
<label for="name" style="font-family:var(--ff-philosopher);color: black;">Name</label>
<input type="text" id="name" name="name" placeholder="Enter your name" required style="font-family: var(--ff-philosopher);">
<span id="name-error" class="error-message"></span>
</div>
<div class="textfield">
<label for="email" style="font-family: var(--ff-philosopher);color: black;">Email / User Name</label>
<input type="email" id="email" name="email" placeholder="Enter Email / UserName" required style="font-family: var(--ff-philosopher);">
<span id="email-error" class="error-message"></span>
</div>
<div class="textfield">
<label for="password" style="font-family:var(--ff-philosopher);color: black;">Password</label>
<input type="password" id="password" name="password" placeholder="Enter Password" required style="font-family: var(--ff-philosopher);">
</div>

<div class="textfield tooltip">
<label for="password">Password</label>
<input type="password" id="password" name="password" placeholder="Enter Password" title="Special characters are not allowed" required>
<span id="password-error" class="error-message"></span>
<span class="tooltiptext">Special characters such as /[<>"/]/ are not allowed</span>
</div>

<button type="submit" class="btn-login" style="font-family: var(--ff-philosopher);color: #ddd;">Register</button>
</form>
<button id="google-login" style="font-family: var(--ff-philosopher);color: #ddd;">Signup with Google</button>
Expand Down