diff options
Diffstat (limited to 'client.js')
-rwxr-xr-x | client.js | 24 |
1 files changed, 15 insertions, 9 deletions
@@ -144,7 +144,7 @@ function sendfile(fname,retries){ }); res.on("end",function(){ if(res.statusCode!=200){ - if(retries>0)sendfileChallenge(fname,challenge,retries-1); + if(retries>0)sendfile(fname,retries-1); else { dialog.warn("Could not upload image! Are your credentials still okay?\n\n"+body); return; @@ -183,7 +183,8 @@ function userExists(userid,cb){ req.end(); } -function checkLogin(userid,password,cb){ +function checkLogin(userid,password,cb,retries){ + retries=retries!=null?retries:3; getchallenge(function(challenge){ var req=http.request({ hostname:HOSTNAME, @@ -192,8 +193,10 @@ function checkLogin(userid,password,cb){ method:"GET" },function(res){ if(res.statusCode==200)cb(true); - else if(res.statusCode==404||res.statusCode==403)cb(false); - else { + else if(res.statusCode==404||res.statusCode==403){ + if(retries>0)checkLogin(userid,password,cb,retries-1); + else cb(false); + } else { console.log("Server returned status code "+res.statusCode+" for checklogin query!"); } }); @@ -235,11 +238,14 @@ function registerUser(userid,password){ process.stdout.write("Username? "); userid=kbd.getLineSync().replace(/[^a-zA-Z0-9_-]/g,""); process.stdout.write("Password? "); -var hasher=crypto.createHash("sha512"); -kbd.setEcho(false); -hasher.update(kbd.getLineSync()); -kbd.setEcho(true); -password=hasher.digest("hex"); +(function(){ + var hasher=crypto.createHash("sha256"); + kbd.setEcho(false); + var passinput=kbd.getLineSync(); + hasher.update(passinput); + kbd.setEcho(true); + password=hasher.digest("hex"); +})(); console.log("\nChecking existence..."); userExists(userid,function(exists){ |