Simple Login And Registration In Blockchain

Create user authentication in blockchain using solidity and remix ide

2022-09-19 03:17:54 - Python V

// SPDX-License-Identifier: GPL-3.0


pragma solidity 0.8.8;


contract AuthSystem{

    struct Users{

        string username;

        uint256 password;

    }


    Users[] public AllUsers;


    function CreateAccount(string memory _username, uint256 _password) public{

        AllUsers.push(Users(_username, _password));

    }


    function Login(string memory _username, uint256 _password) public view returns(string memory){

        for (uint256 i = 0; i < AllUsers.length; i++){

            if(keccak256(abi.encodePacked(AllUsers[i].username)) == keccak256(abi.encodePacked(_username))){

                if(AllUsers[i].password == _password){

                    return 'Logged in';

                }else{

                    return 'User found but Incorrect Password';

                }

            }

        }


        return 'User Not Found';

    }

}


I take lessons on various blockchain courses reach out to me @ nablintech@gmail.com

More Posts