I am a beginner and I need your help.
I created a system: registration, login and forgotten password for applications using Apps Script. User data will be stored in Google Spreadsheet.
However, there was a problem.
Script (in Apps Script) and block designer as shown in the following image:
Please help me..
The problem that occurred was: When I tried to fill in the initial data for registration for the first time and I clicked on registration, the notification Email sudah ada ("Email already exists") appeared. Meanwhile, the Google spreadsheet is empty.
I did the above experiment repeatedly, the results were the same. As shown in the following two pictures:
generally to access a webpage stored in the asset we use this path: http://localhost/YOURFILENAME.html
and some advice: never store a password as plain text in any database, always store the hash value of the password... there are several extensions around, which can provide hash values, for example my tools extension App Inventor Extensions: Tools | Pura Vida Apps
Uses a javascript function to generate the hmacsha256 hash on the app side.
Only downside is that the reset password is sent in plain text in the email...
There are better password generators out there...
SCRIPT
function doPost(e) {
var ss = SpreadsheetApp.openById('YOUR SPREADSHEET ID HERE');
var sh = ss.getSheetByName("YOUR SHEET NAME HERE");
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 = "user logged in";
}
}
}
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 App","Your new password is: " + newpass + "\n\n Use this new password to login.\n\n Thank you.");
}
return ContentService.createTextOutput(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;
}
Thank you very much Mr/Mrs.
I will try, and because I am still a beginner, please help if I encounter obstacles. My hope is that Mr will be willing to help.
function doPost(e) {
var ss = SpreadsheetApp.openById('13FUnFMaNA-8kmLlIg06rlWw3IfXjqLV4a2x6c9wIl2g');
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 = "user logged in";
}
}
}
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 App","Your new password is: " + newpass + "\n\n Use this new password to login.\n\n Thank you.");
}
return ContentService.createTextOutput(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;
}
here's the weblink i tried running , please help me, what to do, can we contact via google meet?