Hello, I hope you'll do good.
I am on a project that makes users to register and login and all the credentials are stored in a Google spreadsheet using an app script.
I am new to this, can you please provide more help, thank you.
function doPost(e) {
var ss = SpreadsheetApp.openById('1K3zIwnKB9IjjNqS7HWZowy5aQcmyoOjo2ILJy6Feytqg');
var sh = ss.getSheetByName("Sheet1");
var msg;
if (e.parameter.fn == "getusers" ) {
var loginData = sh.getDataRange().getValues();
var users = [];
for ( var i = 1; i < loginData.length; i++ ) {
users.push(loginData[i][0]);
}
msg = JSON.stringify(users);
}
else if ( e.parameter.fn == "register" ) {
sh.appendRow([e.parameter.email,e.parameter.pass]);
msg = "user registered";
}
else if ( e.parameter.fn == "login" ) {
var loginData = sh.getDataRange().getValues();
for ( var i = 0; i < loginData.length; i++ ) {
if ( e.parameter.email == loginData[i][0] && e.parameter.pass == loginData[i][1] ) {
msg = { success: true, link: loginData[i][2] };
}
}
}
else if ( e.parameter.fn == "reset" ) {
var newpass = makePasswd();
var newHash = makeHash(newpass,e.parameter.key);
//change hash for email in sheet
var loginData = sh.getDataRange().getValues();
for ( var i = 0; i < loginData.length; i++ ) {
if ( e.parameter.email == loginData[i][0]) {
var rngp = sh.getRange(i+1,2);
rngp.setValue(newHash);
msg = "password reset";
}
}
//send email with new password
GmailApp.sendEmail(e.parameter.email,"From AI2","Your new password is: " + newpass + "\n\n Use this new password to login.\n\n Thank you.");
}
return ContentService.createTextOutput(JSON.stringify(msg));
}
function makePasswd() {
var passwd = '';
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!.#*@_';
for (i=1;i<8;i++) {
var c = Math.floor(Math.random()*chars.length + 1);
passwd += chars.charAt(c)
}
return passwd;
}
function makeHash(message,key){
var getHash = Utilities.computeHmacSha256Signature(message,key).reduce(function(str,chr){
chr = (chr < 0 ? chr + 256 : chr).toString(16);
return str + (chr.length==1?'0':'') + chr;
},'');;
return getHash;
}
your result will be returned in a table in csv format
after fixing your initial bug (the DOCTYPE error) then you should use the "list from csv table" block to convert the csv table into a list... you are currently using the "list to csv table" block...