Я довольно новый разработчик и пытаюсь создать страницу входа. Я хотел использовать JS, чтобы: 1) сравнить psw с psw-repeat, чтобы убедиться, что они одинаковы, и 2) сохранить данные в локальном документе для последующего извлечения. 3) Сравните данные для входа в систему и, если значения верны, переместите пользователя в MainPage.html (не опубликовано).
Честно говоря, не знаю, каких ответов я ожидаю, но мне было бы полезно получить толчок в правильном направлении, поскольку у меня нет большого опыта в JS. Спасибо!
body{
margin: 0;
padding: 0;
font-family: sans-serif;
background: #34495e;
}
.box{
width: 300px;
padding: 40px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #191919;
text-align: center;
}
.box h1{
color: white;
text-transform: uppercase;
font-weight: 500;
}
.box input[type = "text"],.box input[type = "password"]{
border: 0;
background: none;
display: block;
margin: 20px auto;
text-align: center;
border: 2px solid #3498db;
padding: 14px 10px;
width: 200px;
outline: none;
color: white;
border-radius: 24px;
transition: 0.25s;
}
.box input[type = "text"]:focus,.box input[type = "password"]:focus{
width: 280px;
border-color: #2ecc71;
}
.box input[type = "submit"]{
border: 0;
background: none;
display: block;
margin: 20px auto;
text-align: center;
border: 2px solid #2ecc71;
padding: 14px 20px;
outline: none;
color: white;
border-radius: 24px;
transition: 0.25s;
cursor: pointer;
}
.box input[type = "submit"]:hover{
background: #2ecc71;
}
/* Full-width input fields - BEGIN SIGN UP CSS */
input[type=text], input[type=password] {
width: 98%;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
border: none;
background: #f1f1f1;
}
/* Add a background color when the inputs get focus */
input[type=text]:focus, input[type=password]:focus {
background-color: #ddd;
outline: none;
}
/* Set a style for all buttons */
button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.85;
}
button:hover {
opacity:1;
}
/* Extra styles for the cancel button */
.cancelbtn {
padding: 14px 20px;
background-color: #f44336;
}
/* Float cancel and signup buttons and add an equal width */
.cancelbtn, .signupbtn {
float: left;
width: 50%;
}
/* Add padding to container elements */
.container {
padding: 50px;
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: #34495e;
padding-top: 50px;
}
/* Modal Content/Box */
.modal-content {
background-color: #191919;
color: white;
margin: 5% auto 15% auto; /* 5% from the top, 15% from the bottom and centered */
width: 80%; /* Could be more or less, depending on screen size */
}
/* Style the horizontal ruler */
hr {
border: 1px solid #f1f1f1;
margin-bottom: 25px;
}
/* The Close Button (x) */
.close {
position: absolute;
right: 35px;
top: 15px;
font-size: 40px;
font-weight: bold;
color: #f1f1f1;
}
.close:hover,
.close:focus {
color: #f44336;
cursor: pointer;
}
/* Clear floats */
.clearfix::after {
content: "";
clear: both;
display: table;
}
/* Change styles for cancel button and signup button on extra small screens */
@media screen and (max-width: 300px) {
.cancelbtn, .signupbtn {
width: 100%;
}
}
</style>
<!DOCTYPE html>
<html lang = "en" dir = "ltr">
<head>
<meta charset = "utf-8">
<title>Test Animated Login Form</title>
<link rel = "stylesheet" href = "style.css">
</head>
<body>
<form class = "box" action = "index.html" method = "POST">
<h1>Login</h1>
<input type = "text" name = "" placeholder = "Email">
<input type = "password" name = "" placeholder = "Password">
<input type = "submit" value = "Login">
</form>
<button onclick = "document.getElementById('id01').style.display='block'" style = "width:auto;" background = "none">Sign Up</button>
<div id = "id01" class = "modal">
<span onclick = "document.getElementById('id01').style.display='none'" class = "close" title = "Close Modal">×</span>
<form class = "modal-content" action = "/action_page.php">
<div class = "container">
<h1>Sign Up</h1>
<p>Please fill in this form to create a local account.</p>
<hr>
<label for = "email"><b>Email</b></label>
<input type = "text" placeholder = "Enter Email" name = "email" required>
<label for = "psw"><b>Password</b></label>
<input type = "password" placeholder = "Enter Password" name = "psw" required>
<label for = "psw-repeat"><b>Repeat Password</b></label>
<input type = "password" placeholder = "Repeat Password" name = "psw-repeat" required>
<label for = "api-key"><b>Binance API Key</b></label>
<input type = "text" placeholder = "Enter API Key" name = "api-key" required>
<label for = "secret-key"><b>Binance Secret Key</b></label>
<input type = "text" placeholder = "Enter Secret Key" name = "secret-key" required>
<div class = "clearfix">
<button type = "button" onclick = "document.getElementById('id01').style.display='none'" class = "cancelbtn">Cancel</button>
<button type = "submit" class = "signupbtn">Sign Up</button>
</div>
</div>
</form>
</div>
<script>
// Get the modal
var modal = document.getElementById('id01');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>
@seesharper Мне это хорошо известно. В настоящее время я хочу сохранить его локально и намерен позже запускать весь ввод пользователя через криптографическую программу. Это чисто для меня получение опыта.
Вы не должны хранить пароль в локальном хранилище, поскольку он доступен для всех, кто использует компьютер, и для любого вредоносного javascript.