HTML/Java help needed

Thread Starter

Martyk

Joined Jul 23, 2009
7
Hello

I have an ethernet relay board (RobotShop dS1242).

The setup for secure remote access is to write a cookie to my PC, which can then be executed to load the password into the browser everytime I want to
access the board.
But the cookie does not execute correctly, ie it doesn't load the password.
Can some one look at the code and tell me what is going on?
Thanks


<!DOCTYPE HTML>
<html>
<head>
<title>Password Setup</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
Local Storage Available:
<div id='avail'>?</div><br>
Old password was:
<div id='old'>?</div><br>
Password to store is:
<div id='password'>xxxxxxxxx</div><br>
Stored password is:
<div id='storedpassword'>?</div> <br>
<script>
if(typeof(Storage) !== "undefined") {
document.getElementById('avail').innerHTML = "Yes";
} else {
document.getElementById('avail').innerHTML = "No";
}
document.getElementById('old').innerHTML = localStorage.pword;
var pw = document.getElementById('password').innerHTML;
localStorage.pword = pw;
document.getElementById('storedpassword').innerHTML = localStorage.pword;
</script>
</body>
</html>


----------------------------------------
RESULTS:
Local storage avail:
Yes

Old password was:
?

Password to store is:
xxxxxxxxx

Stored password is:
?

---------------------------------------------

All I really need is a simple HTML/Java file with the password hard-coded.

Can some one help?

Thanks
Marty
Montreal, Canada
 

xox

Joined Sep 8, 2017
372
Well you definitely DO NOT want to hard-code the password into the page. That would allow anyone to simply view the source to find out what it is. Anyway most browsers can be automatically configured to ask to store credentials so all you really need to do is imbed a form with a password field and a submit button and you're good to go. That said you can still do all of that manually, though it can get a little messy.

Here's a crude example:

Code:
<!DOCTYPE HTML>
<html>
<head>
<title>Password Setup</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script>
    function field(id)
    {
        return document.getElementById(id);
    }
    function get(id)
    {
        return field(id).value;
    }
    function set(id, value)
    {
        field(id).value = value;
    }
    function password(value)
    {
        if(value != null)
            localStorage.pword = value;
        return localStorage.pword;
    }
    function setup()
    {
        var pword = password();
        if(pword)
        {
            set("pass", pword);
            set("state", "logout");
        }
        else
            set("state", "login");     
/*
        Setup the rest of the page here...
*/
    } 
    function process()
    {
        if(get("state") == "login")
        {
            password(get("pass"));
/*
        Do the rest of the login stuff here...
*/
            set("state", "logout");
        }
        else
        {
            password("");
/*
        Do the rest of the logout stuff here...
*/
            set("state", "login");
        }
    }
    function toggle_password_visibility()
    {
        if(get("visibility") == "hide")
        {
            field("pass").type = "password";
            set("visibility", "show");         
        }
        else
        {     
            field("pass").type = "text";
            set("visibility", "hide");     
        }
    }
    </script>
</head>
<body onload = "setup()">
<!--
    Note: We set the form 'action' to "javascript:void(0)" in order to prevent the page from reloading upon submit.
    Remove if you want it to do otherwise...
-->
    <form onsubmit = "process()" action = "javascript:void(0)">
        Password:
        <input type = "password" id = "pass" onfocus = "this.select()">
        <input type = "button" id = "visibility" value = "show" onclick = "toggle_password_visibility()">
        <input type = "submit" id = "state">
    </form>
</body>
</html>
 
Last edited:

Thread Starter

Martyk

Joined Jul 23, 2009
7
Well you definitely DO NOT want to hard-code the password into the page. That would allow anyone to simply view the source to find out what it is. Anyway most browsers can be automatically configured to ask to store credentials so all you really need to do is imbed a form with a password field and a submit button and you're good to go. That said you can still do all of that manually, though it can get a little messy.

Here's a crude example:

Code:
<!DOCTYPE HTML>
<html>
<head>
<title>Password Setup</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script>
    function field(id)
    {
        return document.getElementById(id);
    }
    function get(id)
    {
        return field(id).value;
    }
    function set(id, value)
    {
        field(id).value = value;
    }
    function password(value)
    {
        if(value != null)
            localStorage.pword = value;
        return localStorage.pword;
    }
    function setup()
    {
        var pword = password();
        if(pword)
        {
            set("pass", pword);
            set("state", "logout");
        }
        else
            set("state", "login");    
/*
        Setup the rest of the page here...
*/
    }
    function process()
    {
        if(get("state") == "login")
        {
            password(get("pass"));
/*
        Do the rest of the login stuff here...
*/
            set("state", "logout");
        }
        else
        {
            password("");
/*
        Do the rest of the logout stuff here...
*/
            set("state", "login");
        }
    }
    function toggle_password_visibility()
    {
        if(get("visibility") == "hide")
        {
            field("pass").type = "password";
            set("visibility", "show");        
        }
        else
        {    
            field("pass").type = "text";
            set("visibility", "hide");    
        }
    }
    </script>
</head>
<body onload = "setup()">
<!--
    Note: We set the form 'action' to "javascript:void(0)" in order to prevent the page from reloading upon submit.
    Remove if you want it to do otherwise...
-->
    <form onsubmit = "process()" action = "javascript:void(0)">
        Password:
        <input type = "password" id = "pass" onfocus = "this.select()">
        <input type = "button" id = "visibility" value = "show" onclick = "toggle_password_visibility()">
        <input type = "submit" id = "state">
    </form>
</body>
</html>
Well you definitely DO NOT want to hard-code the password into the page. That would allow anyone to simply view the source to find out what it is. Anyway most browsers can be automatically configured to ask to store credentials so all you really need to do is imbed a form with a password field and a submit button and you're good to go. That said you can still do all of that manually, though it can get a little messy.

Here's a crude example:

Code:
<!DOCTYPE HTML>
<html>
<head>
<title>Password Setup</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script>
    function field(id)
    {
        return document.getElementById(id);
    }
    function get(id)
    {
        return field(id).value;
    }
    function set(id, value)
    {
        field(id).value = value;
    }
    function password(value)
    {
        if(value != null)
            localStorage.pword = value;
        return localStorage.pword;
    }
    function setup()
    {
        var pword = password();
        if(pword)
        {
            set("pass", pword);
            set("state", "logout");
        }
        else
            set("state", "login");    
/*
        Setup the rest of the page here...
*/
    }
    function process()
    {
        if(get("state") == "login")
        {
            password(get("pass"));
/*
        Do the rest of the login stuff here...
*/
            set("state", "logout");
        }
        else
        {
            password("");
/*
        Do the rest of the logout stuff here...
*/
            set("state", "login");
        }
    }
    function toggle_password_visibility()
    {
        if(get("visibility") == "hide")
        {
            field("pass").type = "password";
            set("visibility", "show");        
        }
        else
        {    
            field("pass").type = "text";
            set("visibility", "hide");    
        }
    }
    </script>
</head>
<body onload = "setup()">
<!--
    Note: We set the form 'action' to "javascript:void(0)" in order to prevent the page from reloading upon submit.
    Remove if you want it to do otherwise...
-->
    <form onsubmit = "process()" action = "javascript:void(0)">
        Password:
        <input type = "password" id = "pass" onfocus = "this.select()">
        <input type = "button" id = "visibility" value = "show" onclick = "toggle_password_visibility()">
        <input type = "submit" id = "state">
    </form>
</body>
</html>
 
Top