Loading...
pragma solidity ^0.8.5;
contract hash {
mapping(uint24 => mapping(uint256 => uint24)) user;
uint24 id = 0;
function _generatehash(string memory _str) private view returns(uint256) {
return uint256(keccak256(abi.encodePacked(_str)));
}
function create_user(string memory username,uint24 age) public returns(bool) {
uint256 random = _generatehash(username);
user[id][random]=age;
id++;
}
function retrive_user(string memory username,uint24 usr_id) public view returns(uint24) {
uint256 random = _generatehash(username);
return user[usr_id][random];
}
}
kecc256 is function which is used to generate cryptographic hash value from given input. As we see in above code _generatehash function is present which return a hash value of string which is unique for every string .just change in one word any number in string or number generates completly different hash value .return type of this function is uint256 .
In above code I am generating hash value of username which points to age of that user. Id is present for pointing to perticular user in mapping.