【问题标题】:Is it possible to add JWT authentication to hard-coded front-end username and password authentication?是否可以将 JWT 身份验证添加到硬编码的前端用户名和密码身份验证中?
【发布时间】:2017-08-29 22:58:45
【问题描述】:

我是编码新手,但我在我的网站上编写了以下用户名和密码验证。

<table>
            <form name="login">
            <tr><th colspan="2">Login</th></tr>
            <tr><td>Username:</td>
            <td><input type="text" name="username"/></td></tr>
            <tr><td>Password:</td>
            <td><input type="password" name="password"/></td></tr>
            <td colspan="2"><center><input type="button" onclick="check(this.form)" value="Submit"/>
            <input type="reset" value="Reset"/></center></td>
        </form>
    </table>
    <script>
        function check(form)
        {
            if(form.username.value == "user1" && form.password.value == "user1")
            {
                location="index.html"
            }
                else
                {
                    alert("Incorrect credentials.")
                }
        }
    </script>

是否可以为此添加 JWT 身份验证?

【问题讨论】:

    标签: java html authentication token jwt


    【解决方案1】:

    你应该不要那样做

    源代码中的“硬编码”凭据通常是个坏主意。可以查看已交付页面源的每个人(可能是每个人)都可以查看您的凭据!

    使用令牌实现这种检查毫无意义,JWT 身份验证流程比您简单的字符串比较复杂得多。首先,您必须在身份验证服务处请求令牌,以某种方式将其存储在客户端(例如本地存储或 cookie),然后在标头中的每个(HTTPS)请求中重新发送它。令牌的有效性也有时间限制,所以即使“硬编码”可以工作(这不会),它也不会永远工作,所以刷新策略也是必须处理的。

    看看一些 JWT 流程解释,可能是 herehere。这应该会让事情更清楚。

    【讨论】:

      猜你喜欢
      • 2018-07-13
      • 1970-01-01
      • 2019-03-15
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      • 2015-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多