0
function registerUser(
        address _address,
        string memory _name,
        string memory _email,
        string memory _password
        // string memory _ipfsImageHash
    ) public returns (bool) {
        require(User[_address].UserAddress != msg.sender);
        User[_address].UserAddress = _address;
        User[_address].name = _name;
        User[_address].email=_email;
        User[_address].password = _password;
        // User[_address].ipfsImageHash = _ipfsImageHash;
        User[_address].isUserLoggedIn = false;
        User[_address].id=User_arr.length;

        emit RegNewUser(
        User[_address].id,
        User[_address].UserAddress,
        User[_address].name,
        User[_address].email,
        User[_address].password
        
        );
       User_arr.push(User[_address]);
        return true;
    }

    // User login function
    function loginUser(string memory _name, string memory _password)
        public
        returns (bool)
    {
        address _address=msg.sender;
        if (
            keccak256(abi.encodePacked(User[_address].password)) == keccak256(abi.encodePacked(_password)) && User[_address].name ==_name
        ) {
            User[_address].isUserLoggedIn = true;
            return User[_address].isUserLoggedIn;
        } else {
            return false;
        }
    }

Here I want to confirm user inserts the password and user name equal or not into the user mapping address name and password. plz, help me to solve this problem.

5
  • 1. It is advisable to show the entire contract code 2. Compare the username via keccak256, as well as the password.
    – Mad Jackal
    Commented Dec 14, 2021 at 7:16
  • ok. I will update Commented Dec 14, 2021 at 7:45
  • you are aware that you cannot have passwords written on the blockchain? any data goes in and out is public
    – Majd TL
    Commented Dec 14, 2021 at 8:44
  • Actually, I do not understand what you said? Commented Dec 14, 2021 at 13:44
  • @MadJackal Thank you for your advice it worked but I don't know what is the reason for that. Commented Dec 14, 2021 at 15:45

1 Answer 1

0

Actually, I got an answer for that. I use kekka 256 hash encode for name also then it is compiled but I don't know what is the reason for that. @madjackle thanks for your advice. Correct code answer given below.

function loginUser(string memory _name, string memory _password)
        public
        returns (bool)
    {
        address _address=msg.sender;
        if (
            keccak256(abi.encodePacked(User[_address].password)) == keccak256(abi.encodePacked(_password)) && keccak256(abi.encodePacked(User[_address].name)) ==keccak256(abi.encodePacked(_name))
        ) {
            User[_address].isUserLoggedIn = true;
            return User[_address].isUserLoggedIn;
        } else {
            return false;
        }
    }

Not the answer you're looking for? Browse other questions tagged or ask your own question.