Register Login Problem

Hi, I try to follow the tutorial on the register and login from here: METRIC RAT AI2 - Google Sheets - Register & Login

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?

RegisterLogin.aia (10.9 KB)
google sheet link: Register Login - Google Sheets

Google Script:

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}}();

In your Web.GotText, why you need to call login function?

image

I checked the code, it looks like you are making your work too complicated.

  1. To check a password is strong or not, use a regex extension

  2. to encode your password, use a Sha1 or sha256 with extension.

  3. In your Web.GotText, after you already login, why you need to call login function?

That calls the hash decryption procedure

for what? user already login or not?

I not sure why when i test it always login failed and I not sure where i doing wrong......

Have you done all this correctly?

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.

I have just tested the Demo aia project supplied, this works OK for Register and Login

why not hash password first then send to server and compare them at server side.

Then it is possible for sheet / script owner to intercept the password (in the script). In this demo, the password never leaves the app, unencrypted.

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.

1 Like




the picture above show that i try testing, for registration is okay, however when login, although the password is correct, still not able to login

What locale/language do you have on your spreadsheet ? I have not tested it with anything other than English (UK)

image

I try to change the locale/language to Unite Kingdom (UK), however the problems also not able to solve... still not able to login

Show your webviewstringchange event block and contents

can i ask where is 'webviewstringchange' located?

Starts like this:

Also show screenshot of spreadsheet, including header row

1
3

Everything appears to be OK.

All I can suggest is if you can export your aia project and send it to me via private message, I can then take a look.