I am making a databaseless website on aws lambda. A user will be able to post a message. And if he has the right password (which will be a url like example.com/pageid/edit/passwordkey/) he will be able to edit the page too. I want to be able to authenticate a user without a database. I'm using s3 but data on s3 will be public so I cannot store the password in s3.
This is my solution at the moment:
function save(pageid,data){
s3.putObject({Key:pageid,Body:data});
password = sha256(pageid + "SALTPHRASE");
print({password:password});
}
function authenticate(pageid,password,newdata){
if(sha256(pageid+"SALTPHRASE") == password){
s3.putObject({Key:pageid,Body:newdata});
}
}
Problem with this approach is if at any future date someone learn the saltphrase. They can access every data on the website because pageid's are public.
I am not good at encryption subject, I have some basic understanding only so I'm not sure if this can work. And how can I make it on nodejs. To be more specific I want to generate public and private keys using SSL like encryption. So that I'm not dependent on one single salt that I cannot change in future.
- I generate a public and private key
- I save the public key with the file, give private key to the user
- When I am authenticating I simply encrypt a message with public key on the file and decrypt it with user provided private key. If message is the same I authenticate the user.
I do not know which libraries can do this (more specifically in nodejs). Which method of encryption is the best or if this method has it's own weaknesses.
Thank you.