however, during testing, i only able to insert data inside the google sheet, and when i try to login, the result will be always login failed, do i miss any step that cause this problem?
function doGet(e) {
var ss = SpreadsheetApp.openById('1CyqJAql8A8IJ5nB6ykKaocsUNAYaNxRojzBCHmlA6dM');
var sheet = ss.getSheetByName("Sheet1");
if ( e.parameter.func == "register" ) {
var uid = getUID();
var user = e.parameter.user ;
var passwd = e.parameter.passwd;
sheet.appendRow([uid,user,passwd]);
msg = "New User Added";
}
else if (e.parameter.func == "getusers" ) {
var loginData = sheet.getDataRange().getValues();
var users = "";
for ( var i = 1; i < loginData.length; ++i ) {
users += loginData[i][1] + ",";
msg = users;
}
}
else if ( e.parameter.func == "login" ) {
var uid;
var user = e.parameter.user;
var passwd;
var loginData = sheet.getDataRange().getValues();
for ( var i = 0; i < loginData.length; ++i ) {
if ( user === loginData[i][1]) {
uid = loginData[i][0];
passwd = loginData[i][2];
msg = "gotPass, "+ uid + "," + user + "," + passwd;
}
}
}
return ContentService.createTextOutput(msg);
}
function getUID() {
for(var newID,success=!1;!success;)20==(newID=generatePushID()).length&&(newID,success=!0);
return newID;
}
//and uid generator (thank you Firebase Developers):
generatePushID=function(){
var r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",e=0,t=[];
return function(){var o=(new Date).getTime(),n=o===e;e=o;for(var a=new Array(8),h=7;h>=0;h--)a[h]=r.charAt(o%64),o=Math.floor(o/64);
if(0!==o)throw new Error("convert entire timestamp");
var f=a.join("");if(n){for(h=11;h>=0&&63===t[h];h--)t[h]=0;t[h]++}else for(h=0;h<12;h++)t[h]=Math.floor(64*Math.random());
for(h=0;h<12;h++)f+=r.charAt(t[h]);
return f}}();
User types in their login name and password
Web component/script returns list of uid,name, hashed password
On return webviewer runs the javascript to test the password against the decrypted hash
If decrypted hash matches the supplied password then user is logged in
yes all should be correct because when register, it able to insert data to the google sheet.
I am thinking is that because of the part of encrpt/decrypt something i miss, so it cause it always login failed.
maybe you misunderstand hash and encryption. hash is one way, send hash code and save hash code is safe. Server owner will not get the password.
but encryption is two way, owner can decrypt the password if he know the algorithm and salt.