Guest User

Untitled

a guest
Oct 20th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. # client:
  3.  
  4. var username = 'user input value';
  5. var password = 'user input value';
  6.  
  7. var nonce = server.getNonce();
  8. var password_nonce_hash = sha1(sha1(password) + nonce);
  9.  
  10. server.authenticate(username, nonce, password_nonce_hash);
  11.  
  12.  
  13. # server:
  14.  
  15. var password_hashes = {
  16.   'jankuca': sha1('user input value')
  17. };
  18. var nonces = [ 'generated value' ];
  19.  
  20. getNonce: function () {
  21.   var nonce = Math.random();
  22.   nonces.push(nonce);
  23.   return [ 200, nonce ];
  24. }
  25.  
  26. authenticate: function (username, nonce, password_nonce_hash) {
  27.   var nonce_index = nonces.indexOf(nonce);
  28.   if (nonce_index === -1) {
  29.     return [ 400, 'Invalid nonce' ];
  30.   }
  31.  
  32.   delete nonces[nonce_index];
  33.  
  34.   var expected_password_nonce_hash = sha1(password_hash + nonce);
  35.   if (expected_password_nonce_hash === password_nonce_hash) {
  36.     return [ 200 ];
  37.   }
  38.   return [ 403, 'Wrong password' ];
  39. }
Add Comment
Please, Sign In to add comment