HTTP的密码验证方法和使用
2016-08-08 16:55
387 查看
//在cocos creator中将数据传入服务器中. 利用editBOX创建输入框
cc.find("Canvas/loginClient/Button").on(cc.Node.EventType.TOUCH_START, function (event) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
var response = xhr.responseText;
console.log(response);
}
};
xhr.open("POST", "http://127.0.0.1:8081/", true); //服务器地址
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
cc.log("帐号 : ",cc.find("Canvas/loginClient/name").getComponent(cc.EditBox).string)
var datas = 'name='+cc.find("Canvas/loginClient/name").getComponent(cc.EditBox).string+'&psw='+cc.find("Canvas/loginClient/Password").getComponent(cc.EditBox).string //传入帐号和密码在服务器上.
xhr.send(datas);
})
// 服务器
var http = require("http")
const url = require('url');
const qs = require('querystring');
http.createServer(function (request, response) {
response.setHeader("Access-Control-Allow-Origin", "*");
response.writeHead(200, {'Content-Type': 'text/plain'});
request.setEncoding('utf-8');
var postData = "";
request.addListener("data", function (postDataChunk) {
postData += postDataChunk;
});
request.addListener("end", function () {
var params = qs.parse(postData);
console.log(ob, params.name);
var ob = getUserObByName(params.name,params.psw)
if(ob == null){
response.end("not found\n") // 接受检测值,并且进行判定,将输出值返回客户端.
}else{
response.end("found !\n")
}
})
}).listen(8081);
function getUserObByName(name,psw){
var returnOb = null
for(var index in userData){ // 进行将传入的帐号和密码进行检测,将检测值返回
var ob = userData[index]
//console.log(ob.name, name);
if( ob.name == name && ob.psw == psw){
returnOb = ob
}
}
return returnOb
}
var userData = [{name:"laowang", psw:"123"},{name:"xiaowang",psw:"234"}] //创建的密码账户正确数据.
console.log('Server running at http://127.0.0.1:8081/');
相关文章推荐
- 使用android-async-http-master框架实现手机登陆服务器端密码验证
- php中使用base HTTP验证的方法
- TortoiseGit 使用 HTTP 方式每次 PUSH 无需输入密码的方法
- layui 表单验证旧密码是否输入正确(验证用户名是否被使用,也可以用这种方法)
- TortoiseGit 使用 HTTP 方式每次 PUSH 无需输入密码的方法
- 使用 jQuery 验证密码一致性,正则表达式验证邮箱及手机号的方法
- SVN使用MySQL验证用户名密码(HTTP)
- WCF消息安全模式之自定义用户名密码:Message CustomUserNamePassword wsHttpBinding 使用Windows Services宿主以及客户端免证书验证
- php中使用base HTTP验证的方法
- 【WCF】使用“用户名/密码”验证的合理方法
- layui 表单验证旧密码是否输入正确(验证用户名是否被使用,也可以用这种方法)
- MongoDB使用用户名密码验证的设置方法(windows下)
- "Selenium + Chrome Diver"使用带用户名密码认证的HTTP代理的方法
- jquery利用正则表达式验证密码,手机号(主要是使用方法,正则表达式网上一搜一堆)
- 用HttpPost登陆验证时,用户名和密码放在请求头部header中的处理方法,形式为Authorization: username password。
- rsync windows中使用时,密码文件验证问题解决方法
- 密码相同验证控件的使用方法
- eclipse 中main()函数中的String[] args如何使用?通过String[] args验证账号密码的登录类?静态的主方法怎样才能调用非static的方法——通过生成对象?在类中制作一个方法——能够修改对象的属性值?
- [转自http://jhtchina.cnblogs.com/]Dev里面DataGid控件使用方法之一
- MYSQL用户root密码为空攻击方法 http://www.sevenline.org/blogview.asp?logID=265