administartor aceess?
Closed this issue · 2 comments
can you please tell me how to add administartor acess while uploading certificate???
In your smart contract SimpleStorage.Sol create a getter and setter function for setting the administrator password before allowing certificate upload, so you will have something like this.
mapping (string => adminAcess) admin;
function setAdminAccess(string memory userName, string memory password) public {
admin[userName].password = password;
}
function getAdminAccess(string memory userName, string memory password) public view returns(boolean memory) {
if(keccak256(bytes(admin[userName].password)) == keccak256(bytes(_password)){
return true
else{
return false
}
}
}
Do well to migrate $truffle migrate --reset
and recompile the smart contract $truffle compile
after making these changes
Now in your App.js File in the instantiate contract function after instantiating your contract, you can set the administrator password using
this.simpleStorageInstance.setAdminAccess("administrator", "12345Password", { from: this.state.account }).then((r) => { console.log('password has been set') })
Note if you want to have another page to set password this is what you are going to do, but for prototyping, all I am doing here is setting an administrator password once the page is loaded
The code sets a username - administrator to a password - 12345Password
Next on the upload certificate tab in the render function before allowing the user to upload a certificate you can ask for a username and password, authenticate it first before allowing them proceed to upload.
to authenticate password use this block of code, pass your username and password from the user's input and replace it with usernameFromForm and PasswordFromFrom
this.state.web3.eth.getAccounts((error, accounts) => {
simpleStorage.deployed().then((instance) => {
this.simpleStorageInstance = instance
this.setState({ account: accounts[0] })
// Get the value from the contract
return this.simpleStorageInstance.getAdminAccess.call(usernameFromForm, PasswordFromFrom)
}).then((result) => {
if(result == true){
//password works
}else{
//wrong password
}
return this.setState({ ipfsHash })
})
})
Do well to star this repo if this repo helps, we can help others too.
Thank you so much ,it helped me alot