Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofill of details which has been entered previously, such as login credentials #769

Closed
devraj-kumar opened this issue Jun 15, 2020 · 2 comments

Comments

@devraj-kumar
Copy link

devraj-kumar commented Jun 15, 2020

Use case

In my app the user needs to log in again and again as session expires after inactivity of 1 hour, so if the credentials can appear up as auto-filled automatically so he wouldn't need to type the same things again and again.

Proposal

@tneotia
Copy link

tneotia commented Jun 16, 2020

You could accomplish this using programmatic JS, if you prompt the user for his username and password on the initial setup of the app. Then check if it is correct by performing a test login either through some authentication service that supports Flutter or by listening for URLs - open the login url in the background and then listen to see if the url is redirected to the main page, else tell the user his credentials are incorrect. Finally, with the correct credentials listen for the login url constantly and if it shows up, autofill the username/password and submit the form automatically, and you could hide all this behind a container and a loading spinner.

Example:

flutterWebviewPlugin.evalJavaScript("javascript:var uselessvar =document.getElementsById('email').value='$user_email';");
flutterWebviewPlugin.evalJavaScript("javascript:var uselessvar =document.getElementsById('password').value='$user_password';");
flutterWebviewPlugin.evalJavaScript("javascript:var uselessvar =document.getElementById('remember_me').checked = true;");
flutterWebviewPlugin.evalJavaScript("javascript:var uselessvar =document.getElementById('login_form').submit()");

user_email and user_password are your stored strings.
Depending on the websites html you may need to use getElementsbyName or getElementsbyClass.

@loonix
Copy link

loonix commented Jan 20, 2022

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#never_use_eval!

@tneotia Is evalJavascript the same as the one referenced on that document? What about security, is it safe to send password through it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants