Guest User

Untitled

a guest
Mar 21st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. pragma solidity ^0.4.2;
  2.  
  3. contract Login {
  4. event LoginAttempt(address sender, string challenge);
  5.  
  6. function Login (string challenge) public {
  7. LoginAttempt(msg.sender, challenge);
  8. }
  9.  
  10. }
  11.  
  12. const LoginContract = new web3.eth.Contract(abiLogin);
  13.  
  14. // LoginAttempt is the name of the event that signals logins in the
  15. // Login contract. This is specified in the login.sol file.
  16.  
  17. loginAttempt = LoginContract.LoginAttempt({});
  18.  
  19. challenges = {};
  20. successfulLogins = {};
  21.  
  22. loginAttempt.watch({}, '', function(error, event) {
  23. if(error) {
  24. console.log(error);
  25. return;
  26. }
  27.  
  28. console.log(event);
  29.  
  30. const sender = event.args.sender.toLowerCase();
  31.  
  32. // If the challenge sent through Ethereum matches the one we generated,
  33. // mark the login attempt as valid, otherwise ignore it.
  34. if(challenges[sender] === event.args.challenge) {
  35. successfulLogins[sender] = true;
  36. }
  37. });
Add Comment
Please, Sign In to add comment