passing the encrypted code in url




Asked on June 30, 2020
Hello

I dont want to show the code in url for reset password page. In the mail content if user clicks on reset password link then the code is showing in path of the url. I dont want to show the that code in url. Is there any way to show the code with some encryption ?How to achieve this with html code?
Can anyone please help me in resolving this issue?

Thanks & Regards
Shilpa



Replied on June 30, 2020
In HTML page you can use JavaScript to encrypt the code.
Find the sample encryption code using SHA1



<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/forge/0.8.2/forge.all.min.js"></script>

    <script type="text/Javascript">
    function generateHash()
{
        var plainText = document.getElementById('code').value;
   // var md = forge.md.sha256.create();  
        var md = forge.md.sha1.create();  
        md.start();  
        md.update(plainText, "utf8");  
        var hashText = md.digest().toHex();  
        console.log(hashText);
        alert(hashText);
    }        
    </script>
</head>
<body>
    <input id='code' />
    <button onclick="generateHash()">Encrypt</button>
</body>
</html>





Replied on July 01, 2020
Thank you Amrendra for the solution. I want to pass the code to generateHash() which is in thymeleaf. Can you please suggest how to pass the thymeleaf code to that method.

<a href="http://login.example.com/login/reset_password?code=some_code"
th:href="@{${resetUrl}(code=${code})}">Reset your password</a>




Replied on July 01, 2020
Try this solution.

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/forge/0.8.2/forge.all.min.js"></script>

    <script type="text/Javascript">
      function generateHash(code) {   
        var md = forge.md.sha1.create();  
        md.start();  
        md.update(code, "utf8");  
        var hashText = md.digest().toHex();  
return hashText;
      } 
       
    </script>
    </head>

    <body>

        <a href="" id="resetPwd">Reset your password</a>

  <script th:inline="javascript">

    /*<![CDATA[*/

var encCode = generateHash(/*[[${code}]]*/ 'code');
document.getElementById("resetPwd").href='http://login.example.com/login/reset_password?code=' + encCode;

            /*]]>*/

</script>

    </body>
</html>



Replied on September 16, 2023
Where can I study this topic in detail?

Write Answer










©2024 concretepage.com | Privacy Policy | Contact Us