Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Ethereum Projects for Beginners

You're reading from  Ethereum Projects for Beginners

Product type Book
Published in Jul 2018
Publisher Packt
ISBN-13 9781789537406
Pages 106 pages
Edition 1st Edition
Languages

User identity verification with blockchains


This section takes a closer look at the user verification process and the Solidity code that lies behind it. Let us consider the following Solidity code:

pragma solidity ^0.4.17;
contract UserExample {

 mapping(address => bool) user_verified;
 mapping(address => bytes32) user_codes;

 mapping(bytes32 => address) to_sign;
 mapping(bytes32 => bool) signed;

 address owner;

 modifier onlyOwner() {
 require(msg.sender == owner);
 _;
 }

 function UserExample() public {
 owner = msg.sender;
 }

function addUser(address user, bytes32 hashed_verification) public onlyOwner {
 user_verified[user] = false;
 user_codes[user] = hashed_verification;
 }

 function verify(bytes32 verification_code) public {
 if (user_verified[msg.sender] == false && 
 sha256(verification_code) == user_codes[msg.sender]) {
 user_verified[msg.sender] = true;
 }
 }
}

As you can see, the owner is your own server. The constructor defines the value of the owner...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}