LOGIN AND SIGN UP FINAL ACTIVITY 4
login code
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> Login and Signup </title>
</head>
<style>
body {
font-size: 15px;
background: #000000;
font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}
* {
box-sizing: border-box;
}
h2 {
text-align: center;
text-decoration: underline;
font-family: verdana;
}
input[type=text], input[type=password] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
border: none;
background: #f1f1f1;
}
input[type=text]:focus, input[type=password]:focus {
background-color: #000000;
outline: none;
}
button {
background-color: #003166;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 5px;
cursor: pointer;
width: 100%;
opacity: 0.9;
}
.pindot{
background-color: #003166;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 5px;
cursor: pointer;
width: 100%;
opacity: 0.9;
float: center;
}
button:hover {
opacity:1;
}
form {
width: 500px;
background: #fff;
padding: 0px 40px 40px;
border: 1px solid #ccc;
margin: 5% auto auto auto;
border-radius: 20px;
box-shadow: 0px 0px 20px rgb(0 0 0 / 50%);
}
label {
display: block;
margin-bottom: 5px
}
label i {
color: #003166;
font-size: 80%;
}
input, select {
border: 1px solid #ccc;
padding: 10px;
display: block;
width: 100%;
box-sizing: border-box;
border-radius: 2px;
}
.cancelbtn, .resetbtn {
padding: 14px 20px;
background-color: black;
}
.cancelbtn, .signupbtn {
width: 100%;
}
.container {
width: 300px;
background: #fff;
padding:0px 40px 40px;
border: 1px solid #ccc;
margin: 0px auto 0;
border-radius: 5px;
}
.modal {
display: none;
position: fixed;
background-color: #fff;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
padding: 30px 0px 30px 0px;
}
.modal-content {
background-color: #fefefe;
margin: 1% auto auto auto;
border: 1px solid #888;
width: 80%;
}
hr {
border: 1px solid #f1f1f1;
margin-bottom: 25px;
}
.close {
position: absolute;
right: 35px;
top: 15px;
font-size: 40px;
font-weight: bold;
color: #5c5c5c;
}
.close:hover,
.close:focus {
color: #000;
cursor: pointer;
}
.form-inline {
border: 1px solid #ccc;
padding: 8px 10px 4px;
border-radius: 2px;
}
.form-inline label, .form-inline input {
display: inline-block;
width: auto;
padding-right: 15px;
}
.error {
color: red;
font-size: 90%;
}
@media screen and (max-width: 300px) {
.cancelbtn, .signupbtn {
width: 100%;
}
}
.UWU {
background-color: #003166;
}
</style>
<body>
<form name="form">
<h2>Login</h2>
<p> Log in this website</p>
<div>
<label for="text"> <b> Username </b> </label>
<input id="user" name="user" type="text" placeholder="Username"> </div>
</div>
<div>
<label for="psw"> <b> Password </b> </label>
<input id="pass" name="pass" type="password" placeholder="Password"> </div>
</div>
<div>
<button type="button" value="Login" onClick="validate(this.form)"> Login </button>
<button class="resetbtn" type="Reset"> Reset </button>
<hr>
<p> Don't have an account? <br> Sign up now for free! </p>
<button class="UWU" type="button" onclick="document.location ='Signup.html'">Sign up</button>
</div>
</form>
<script>
function validate(form) {
var credentials = JSON.parse(window.name);
var usernameInput = document.getElementById("user").value;
var passwordInput = document.getElementById("pass").value;
var matchingCredential = credentials.find(x => x.username == usernameInput);
if (matchingCredential == undefined) {
alert('No such user');
return;
}
if (matchingCredential.password == passwordInput) {
alert('Login Successful');
window.location.href = "https://raymarcesta09.blogspot.com/";
}
else {
alert("No such credential");
}
}
var credentials = [];
function signup() {
var passwordPassesCriteria = false;
var passwordMatched = false;
var usernameInput = document.getElementById('username-input').value;
var passwordInput = document.getElementById('password-input').value;
var confirmPasswordInput = document.getElementById('confirm-password-input').value;
passwordMatched = passwordInput == confirmPasswordInput;
var regex = /^[a-zA-Z\s]+$/;
passwordPassesCriteria = regex.test(passwordInput);
console.log(saveCredentials);
if (passwordMatched && passwordPassesCriteria) {
displayFormData(usernameInput, passwordInput);
saveCredentials();
goToLogin();
}
}
function saveCredentials() {
var username = document.getElementById('username-input').value;
var password = document.getElementById('password-input').value;
credentials.push({
username: username,
password: password
});
var objectAsString = JSON.stringify(credentials);
window.name = objectAsString;
}
function displayFormData(username, password) {
var alertMessage = 'Username: ' + username + '\n' +
'Password: ' + password;
alert(alertMessage);
}
function goToLogin() {
window.location.href = 'Lognin.html';
}
function goToSighUp() {
window.location.href = 'Signup.html';
}
</script>
</body>
</html>
Comments
Post a Comment