繁体   English   中英

如何验证用户名和密码

[英]How to validate username and password

我正在使用一个平面 JSON 文件作为我的数据库,我想验证我的 JSON 文件中的用户名和密码,以通过 JavaScript 访问某个 HTML 站点。我的 JSON 数据如下所示:

"1": {
    "username": "Chris1",
    "firstname": "Martin",
    "lastname": "Johnson",
    "age": "30",
    "gender": "Male",
    "interest": "Football",
    "password1": "123456"
  }

任何帮助表示赞赏。

您可以像这样解析 JSON 文件中的数据:

    var Jsonfile = yourJSONfileAsString;
    var obj = JSON.parse(Jsonfile);
    obj.attribute; //access the elemets you want as attributes of the object

我假设您已经拥有可供您的代码处理的 JSON 文件。 如果没有,那么将 JSON 文件发送到前端 JavaScript 代码的方法是使用XMLHttpRequest发出 Http 请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM