Solidity, the primary language for developing smart contracts on blockchain platforms like Celo, offers a variety of data types including Structs and Mappings, which can be used to create more complex and powerful contracts. In this challenge, you will delve into advanced data structures in Solidity by creating a user registration system.
Design a smart contract that simulates a user registration system with the following requirements:
- The contract should allow users to register with their username and a password. The password should be hashed before being stored.
- The contract should use a struct to represent each user, with attributes for the username, hashed password, and registration date.
- The contract should use a mapping to link usernames with their respective user data.
- The contract should allow anyone to check if a username is already registered.
- The contract should prevent the same username from being registered more than once.
- Use the keccak256 function to hash passwords before storing them.
- Use the
nowglobal variable to record the registration date.
msg.senderto identify the address that is interacting with the contract.
requirestatements to enforce that a username is not already taken.
- Correctness: The contract should compile without errors and meet all the requirements.
- Readability: The contract should be well-documented, with comments explaining the code.
- Testability: You should also provide examples of how to test each function of the contract.
Remember, this challenge is a simple exercise and does not include all the best practices needed for a secure, real-world user registration system.
For a comprehensive understanding of Celo smart contracts and Solidity, please refer to the Celo and Solidity documentation.
Please reply with a link to your PR on GitHub - celo-academy/Solidity-Advanced-Data-Structures-Structs-and-Mapping-Coding-Challenge-, including your user registration contract. Also, include any notes or comments you think are necessary to understand your design and choices. Lastly, provide a brief explanation about how each function of the contract should be tested.