the code i made only reads the last index from localStorage for login validation, can someone help to login using all existing data?
$('#btnlogin').click(function(){
var usernamelogin = $('#usernamelogin').val()
var passwordlogin = $('#passwordlogin').val()
var data_user1 = JSON.parse(localStorage.getItem('data_user'))
for(var i in data_user1){
var entry = data_user1[i]
}
if(usernamelogin == entry.username && passwordlogin == entry.password){
alert("Log in successfull")
window.location.href = "curhat.jsp"
}else{
alert("wrong username or password")
}
//console.log(data_user1)
//console.log('username = ' + entry.username)
})
Related
I am trying to have a summary section in my website that will take all the results from other functions and display the information. I created the following functions and call path to try and get this but it appears that the callback is still being called before the largest function finishes.
Office.onReady(info => {
if (info.host === Office.HostType.Outlook) {
document.getElementById("app-body").style.display = "flex";
mainprocessing(finalization);
}
});
function mainprocessing(callback){
console.log("main processing")
reviewEmailInfo();
attachmentCheck();
checkBodyforLinks();
checkmsgforriskywords();
callback();
}
function finalization(){
console.log("entering finalization");
document.getElementById("riskscore").innerHTML = "This email has a riskscore of " + riskScore;
}
I put console.logs into each function at the beginning and end and this is what is in the logs
main processing taskpane.js:43
entering review email taskpane.js:122
entering attachment check taskpane.js:137
leaving attachment check taskpane.js:174
entering check body taskpane.js:192
leaving check body taskpane.js:196
entering check risky words taskpane.js:210
entering leaving check risky taskpane.js:38
entering finalization VM72 taskpane.js:9931
leaving review email VM72 taskpane.js:9002
[WDS] Live Reloading enabled.client:52
[WDS] Live Reloading enabled.
leaving review email taskpane.js:106
function checkBodyforLinks(){
console.log("entering check body");
Office.context.mailbox.item.body.getAsync(
"html",
{ asyncContext: "This is passed to the callback" },
function callback(result) {
var parser = new DOMParser();
var bodyHtml = parser.parseFromString(result.value, "text/html");
//need to add check to ignore mailto: links
var linkDomains = [], links = bodyHtml.links;
document.getElementById("linkCheck").innerHTML = "No links found within email body";
for (var i = 0; i < links.length; i++){
linkDomains.push(links[i].href);
}
if (linkDomains.length > 0){
document.getElementById("linkCheck").innerHTML = "There are " + links.length+1 +"links in the email body";
}
}
);
console.log("leaving check body");
}
console.log("entering review email");
Office.context.mailbox.item.getAllInternetHeadersAsync(
function(asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
var headers = asyncResult.value;
var ReplyTo = headers.replace(" ","").match(/Return-Path:(.*)/);
if (ReplyTo.length != null){
var cleanEmail = ReplyTo[1].substring(1,ReplyTo[1].length);
if(cleanEmail == Office.context.mailbox.item.sender.emailAddress){
document.getElementById("reply-match").innerHTML= "The from and reply email address match";
}else{
riskScore += 5;
document.getElementById("reply-match").innerHTML= "The from and reply email address DO NOT MATCH. The sender is:" + Office.context.mailbox.item.sender.emailAddress + " and the reply addres is: " + cleanEmail;
}
}
var ARCAuthResult = headers.replace(" ","").match(/ARC-Authentication-Results:(.*)/);
var dkimChk = false;
var spfChk = false;
if(ARCAuthResult != null){
if(ARCAuthResult[1].search("spf=pass")){
spfChk = true;
}
if(ARCAuthResult[1].search("dkim=pass")){
dkimChk = true;
}
}else{
var AuthResult = headers.replace(" ","").match(/Authentication-Results:(.*)/);
if(AuthResult.length != null){
if(AuthResult[1].search("spf=pass")){
spfChk = true;
}
if(AuthResult[1].search("dkim=pass")){
dkimChk = true;
}}}
if(spfChk == true & dkimChk==true){
document.getElementById("dkimspfchk").innerHTML = "Both DKIM and SPF are safe";
}else if(spfChk == true){
riskScore += 5;
document.getElementById("dkimspfchk").innerHTML = "DKIM check failed";
}else if(dkimChk == true){
riskScore += 5;
document.getElementById("dkimspfchk").innerHTML = "SPF check failed";
}else{
riskScore += 10;
document.getElementById("dkimspfchk").innerHTML = "SPF amd DKIM check failed";
}
//Check for domain match between sender and reciever
var domainIndex = Office.context.mailbox.item.sender.emailAddress.indexOf("#");
var senderDomain = Office.context.mailbox.item.sender.emailAddress.slice((domainIndex+1), Office.context.mailbox.item.sender.emailAddress.length);
var receiverAddress = headers.replace(" ","").match(/To:(.*)/);
if (receiverAddress.length != null){
domainIndex = receiverAddress[1].indexOf("#");
var recieverDomain = receiverAddress.slice((domainIndex+1),receiverAddress.length-1);
if(senderDomain == recieverDomain){
document.getElementById("domainMatch").innerHTML = "This email comes from with your domain";
}else {
riskScore += 1;
document.getElementById("domainMatch").innerHTML = "This message comes from an external email address";
console.log("risk score after domain " + riskScore);
}
}
//var domainAge = domainWhois(senderDomain);
console.log("leaving review email");
return;
} else {
if (asyncResult.error.code == 9020) {
// GenericResponseError returned when there is no context.
// Treat as no context.
} else {
console.log("error");
}
}
}
);
return;
}
I have two buttons: a sign up and a log in. I intend to collect the input form values from the sign up into an array (this works). I then want to compare the user input from the sign up with the user input from the login and notify the user that they are logged in. (I am yet to get started with localStorage and JSON. I want to get this done using arrays first).
I have tried using a for loop and if statements with logical operators (&&).
$(document).ready(function() {
$("#userSignUp").click(function() {
$("#signUpForm").show();
$("#signup").hide();
});
$("#userInfo").click(function(event) {
var custName = $("#newName").val();
var custEmail = $("#newEmail").val();
var custPass = $("#newPass").val();
var custData = [];
custData.push(custName, custEmail, custPass);
$("#userSignUp").text("Thank you for signing up!");
});
$("#userLogIn").click(function() {
$("#loginForm").show();
$("#login").hide();
});
$("#userData").click(function(event) {
var currentName = $("#userName").val();
var currentEmail = $("#userEmail").val();
var currentPass = $("#userPass").val();
for (var i = 0; i < custData.length; i++) {
if ((currentName === custData[0]) && currentEmail === custData[1] && currentPass === custData[2]) {
$("#userLogIn").text("You are logged in!");
} else {
$("#userLogIn").text("Please enter correct name, email and password!");
}
};
});
});
May be you could try only IF statement without the loop.
The following thing checks if there is such item in the array and if it IS, will do smth:
if (custData.indexOf(currentName) != -1
&& custData.indexOf(currentEmail) != -1
&& custData.indexOf(currentPass) != -1) {
$("#userLogIn").text("You are logged in!");
} else {
$("#userLogIn").text("Please enter correct name, email and password!");
I have been learning about localStorage. I decided to use it on this task. I collected the values that the user inputs when signing up, and 'saved' them on local Storage. I then collected the value the user inputs and 'retrieved' them via local Storage. Here is the code:
$(document).ready(function() {
$("#userSignUp").click(function() {
$("#signUpForm").show();
$("#signup").hide();
});
$("#userInfo").click(function(event) {
var custName = $("#newName").val();
var custEmail = $("#newEmail").val();
var custPass = $("#newPass").val();
localStorage.setItem("name", "Raych") +
localStorage.setItem("email", "raych#gmail.com") +
localStorage.setItem("password", "hey"); ;
$("#userSignUp").text("Thank you for signing up!");
});
$("#userLogIn").click(function() {
$("#loginForm").show();
$("#login").hide();
});
$("#userData").click(function(event) {
event.PreventDefault;
var currentName = $("#userName").val();
var currentEmail = $("#userEmail").val();
var currentPass = $("#userPass").val();
localStorage.getItem("name") +
localStorage.getItem("email") +
localStorage.getItem("password");
$("#userLogIn").text("You are logged in!");
});
});
I'm making a hangman game and would like to store and retrieve the person's score and their username from the local storage and display it on the leader board div. How do I do this? I've seen most people use localStorage.get and localStorage.set but I'm not sure how to implement it here.
Thanks for the help.
This is my javascript code so far:
function storeUserDetails() {
var userObject = {};
userObject.name = document.getElementById("nameinput").value;
userObject.username = document.getElementById("usernameinput").value;
userObject.password = document.getElementById("passinput").value;
userObject.repeatpassword = document.getElementById("repeatpassinput").value;
userObject.topscore = 0;
localStorage[userObject.username] = JSON.stringify(userObject);
document.getElementById("result").innerHTML = "<b>Registration
Successful<br> Please <a href = '../PHP/login.php'><font color =
'orangered'>login</font></a></b>";
}
function checkLogin() {
if (localStorage.loggedInUsername !== undefined) {
var userObj = JSON.parse(localStorage[localStorage.loggedInUsername]);
}
}
function login() {
var username = document.getElementById("usernameinput").value;
if (localStorage[username] === undefined) {
document.getElementById("result").innerHTML = "<b>Username not found. Please sign up.</b>";
return;
} else {
var userObj = JSON.parse(localStorage[username]); //Convert to object
var password = document.getElementById("passinput").value;
if (password === userObj.password) {
localStorage.loggedInUsername = userObj.username;
document.getElementById("result").innerHTML = "";
window.location = "loggedin.php";
/*sessionStorage.setItem('status', 'logged in');*/
} else {
document.getElementById("result").innerHTML = "<b>Password incorrect. Please try again.</b>"
}
}
}
function updateScore() {
rankingTable = document.getElementById("leaderboardcontainer");
tableData = document.getElementById("content");
//Username and score to be displayed here.
}
You should use getItem, setItem and removeItem methods as shown in the documentation.
https://developer.mozilla.org/it/docs/Web/API/Window/localStorage
I am playing around with the local storage on PhoneGap, trying to create a JavaScript login. My current problem is when I run the application, it will not go to the main menu if the username and password is correct.
I believe the problem is with the window.location.href method. I want to navigate to a local page, not an online one.
Van anyone suggest another way to do this?
$(document).ready(function() {
if (typeof(localStorage) === 'undefined' ) {
alert('Your browser does not support HTML5 localStorage. Try upgrading.');
} else {
$("#return_form2").submit(function(){//load the items
getItems();
});
}
});
var getItems = function() {
var timeLog, logLength, i;
i = 0;
logLength = localStorage.length-1; //how many items are in the database starting with zero
timeLog = '';
// loop through each item in the database
for (i = 0; i <= logLength; i++) {
var itemKey, value, values, firstname, password, email;
//variables for the key and values
itemKey = localStorage.key(i);
value = localStorage.getItem(itemKey);
values = JSON.parse(value);
firstname = values.fname;
password = values.pass;
email = values.email;
course = values.class;
var tt = course;
var un = document.return_form2.username.value;
var pw = document.return_form2.password.value;
var web = "Web Systems Development";
if ((un == firstname) && (pw == password) && (tt == web)){
window.location.href = "AppMenu.html";
return false;
}
else {
alert ("Incorrect Password");
}
}}
I'm not sure that ((un == firstname) && (pw == password) && (tt == web)) is true, anyway, the next line worked for me
window.location="AppMenu.html";
Also you don't have to return false
I am having an issue with my cookies and I can't figure it out.
Basically I have it set up so it checks for the cookie to see if the
user is logged in, and then displays either a welcome message or a
login link.
It works - except that instead of returning the persons name in the
welcome message it just is blank where the name should be.
The cookie is there, with all the appropriate info.. not sure what I
am doing wrong.
var itm = new Array();
itm[0] = findCookie("ui");
if (itm[0] == null) {
document.write("<h2><a href='logreg.html'>Log In or Sign Up</a></h2>");
}
else {
var c1 = itm[0].indexOf(",");
var c2 = itm[0].indexOf(",",c1);
var c3 = itm[0].indexOf(",",c2);
var gname = itm[0].substring(c2,c3);
document.write("<h2>Welcome "+gname+"!</h2>");
}
The findCookie function is..
function findCookie(val){
var cookie = null;
var findVal = val + "=";
var dc = document.cookie;
if (dc.length > 0)
{
var start = dc.indexOf(findVal);
if (start >= 0)
{
start += findVal.length;
lastVal = dc.indexOf(";", start);
if (lastVal == -1)
{
lastVal = dc.length;
}
cookie = (dc.substring(start, lastVal));
}
else
{
return cookie;
}
}
return cookie;
}
Never mind - I forgot to add the +1 after it finds the index of the comma or else it just reads the index number for each being the same...