Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.2;
- contract Login {
- event LoginAttempt(address sender, string challenge);
- function Login (string challenge) public {
- LoginAttempt(msg.sender, challenge);
- }
- }
- const LoginContract = new web3.eth.Contract(abiLogin);
- // LoginAttempt is the name of the event that signals logins in the
- // Login contract. This is specified in the login.sol file.
- loginAttempt = LoginContract.LoginAttempt({});
- challenges = {};
- successfulLogins = {};
- loginAttempt.watch({}, '', function(error, event) {
- if(error) {
- console.log(error);
- return;
- }
- console.log(event);
- const sender = event.args.sender.toLowerCase();
- // If the challenge sent through Ethereum matches the one we generated,
- // mark the login attempt as valid, otherwise ignore it.
- if(challenges[sender] === event.args.challenge) {
- successfulLogins[sender] = true;
- }
- });
Add Comment
Please, Sign In to add comment