diff --git a/abhinavs-blog/blog-functionality.js b/abhinavs-blog/blog-functionality.js index 4ba3c3c..396f990 100644 --- a/abhinavs-blog/blog-functionality.js +++ b/abhinavs-blog/blog-functionality.js @@ -1,15 +1,18 @@ //for first time using the database:- -credentialArray = { - "default": "default_pass125" -}; -localStorage.setItem('credentials', JSON.stringify(credentialArray)); -credentialArray = localStorage.getItem('credentials') +// credentialArray = { +// "default": "default_pass125" +// }; +// localStorage.setItem('credentials', JSON.stringify(credentialArray)); +// let credentialArray = JSON.parse(localStorage.getItem('credentials')); + +let credentialArray = JSON.parse(localStorage.getItem('credentials')) || {}; function createUser(userID, pass){ if(credentialArray[userID]){ console.log("User already exists"); } else{ + //checks the strength of the password if(checkStrenth(pass)){ credentialArray[userID] = pass; console.log("User created successfully"); @@ -46,7 +49,7 @@ function checkStrenth(pass){ } } if(hasInt && hasSpclChr && !hasPattern){ - console.log("Has a special character and a number."); + // console.log("Has a special character and a number."); return true; } // FOR DEBUG: @@ -63,3 +66,28 @@ function checkStrenth(pass){ } createUser("Abhinav", "my_passAbhinav123"); +createUser("Abhinav", "sdfds@#Ainav123"); + + + + +//Able to click edit button after entering the correct credentials +//and after that a div apears showing the input fields to fill out the necesarry +//parameters of a blog post. + +const editButton = document.getElementById('myButton'); +//sign in or edit +function editValidate(){ + const username = document.querySelector(".username-field").value; + const password = document.querySelector(".password-field").value; + + if(credentialArray[username] == password){ + alert("logged in"); + window.location = "login-accepted.html"; + } + else{ + alert("wrong username or password"); + } + document.querySelector(".password-field").value = ""; +} +button.addEventListener('click', editValidate); \ No newline at end of file diff --git a/abhinavs-blog/blog.html b/abhinavs-blog/blog.html index 17c80c2..5e6c3bd 100644 --- a/abhinavs-blog/blog.html +++ b/abhinavs-blog/blog.html @@ -25,5 +25,23 @@
+ + + +