Hashing

Posted on February 1, 2015
Tags: hacksoft

1 simple

            function simpleHash(input) {
                var hash = 0;
                if (input.length == 0) return hash;

                for (var i = 0; i < input.length; i++) {
                    var char = input.charCodeAt(i);
                    hash = ((hash << 5) - hash) + char;
                    hash = hash & hash; 
                }

                return hash;
            }

            function checkPassword() {
                const groundtruth = "134354" //<- hash of your password
                let storedPassword = localStorage.getItem('pass');

                if (storedPassword == groundtruth) {
                    document.body.hidden=false;
                    return true
                } else {
                    let password = prompt("input the password");
                    if(password === null){
                        return false
                    }
                    if (simpleHash(password) != groundtruth) {
                        alert("incorrect password");
                        document.body.hidden=true
                        window.location.reload(); // Reload the page
                    }else{
                        localStorage.setItem('pass', simpleHash(password));
                        document.body.hidden=false
                        return true
                    }

                }
                return false
            }
            let goodprompt = checkPassword()
            while(!goodprompt){
                goodprompt = checkPassword()
            };