Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8"/>
- </head>
- <body>
- <form>
- E-MAIL: <input type="text" id="email" placeholder="email"> <br><br>
- HASLO: <input type="password" id="pass"> <br><br>
- POWTORZ HASLO:<input type="password" id="passRep"> <br><br>
- <input type="button" value="REJESTRUJ" id="btn">
- </form>
- <script src="md5.js"></script>
- <script>
- const dbName = "users";
- var btn = document.getElementById("btn");
- console.log(btn);
- function getDb(db){
- if(!localStorage.getItem(db)){
- return false;
- }
- return JSON.parse(localStorage.getItem(db));
- }
- function getUser(email){
- var users = getDb(dbName);
- var user = users.filter(function(user){
- if(user.email == email){ return user }
- })
- }
- btn.addEventListener('click', function(){
- var email= $('#email').val();
- var pass = $('#pass').val();
- var passRep = $('#pass').val();
- var anyErrors = false;
- if(pass != passRep){
- anyErrors = true;
- }
- if(!anyErrors){
- var users = getDb(dbName);
- console.log(users);
- var user = {
- email,
- pass: MD5(pass)
- }
- if(users){
- users.push(user);
- localStorage.setItem(dbName, JSON.stringify(users));
- }else{
- var newUsers = [];
- newUsers.push(user);
- localStorage.setItem(dbName, JSON.stringify(newUsers));
- }
- }
- });
- </script>
- <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement