Friday, June 6, 2014

Re: Making browser save userneme & password

Thanks a lot for your input!  I thought about doing it this way, and I like it a lot for all the reasons you state.  This would be the best and easiest approach.  My only problem with it was that I fear security.  I really don't understand cookies and local storage well.  I could encrypt the password.  I just don't understand if an app from another site can just read my local storage.  Do you have any comments about that concern?

Thank you.

Blake



On Fri, Jun 6, 2014 at 9:10 PM, Thad Humphries <thad.humphries@gmail.com> wrote:
Can you use HTML5? If so, then why not use com.google.gwt.storage.client.Storage? For example in my newer apps, if the login is successful and a checkbox is set, the app remembers the target server and username:

    // set/clear local storage
    final Storage storage = Storage.getLocalStorageIfSupported();
    if (storage != null) {
      if (view.getRememberId().getValue()) {
        storage.setItem("o_username", user);
        storage.setItem("o_server", server);
        view.getRememberId().setValue(true);
      }
      else {
        storage.setItem("o_username", "");
        storage.setItem("o_server", "");
        view.getRememberId().setValue(false);
      }
    }

The next time the user calls up the app, I check local storage for these values:

    // Fetch fields from storage.
    final Storage storage = Storage.getLocalStorageIfSupported();
    if (storage != null) {
      String user = storage.getItem("o_username");
      view.getUsername().setText(user);
      view.getServer().setText(storage.getItem("o_server"));
      if (user != null && !user.isEmpty()) {
        view.getRememberId().setValue(true);
      }
    }

I don't store the password, but I could.

This is a lot less painful than my older approach of injecting HTML (similar to yours) and it's consistent across HTML browsers, include mobile devices using MGWT.

On Tuesday, June 3, 2014 7:12:51 PM UTC-4, Blake wrote:
Greetings,

I would like to have the browser save the username/password to my application.  I have searched and searched and found no solution that works on all of the standard browsers (Chrome, IE, Firefox, Safari).  Best I have been able to do (works on Firefox & IE) is:


....
<form id="login-form" action="login">
    <table>
        <tr>
            <td><button type="button">Continue as a guest</button> &nbsp;&nbsp;or &nbsp;&nbsp;Login ID:</td>
            <td> <input autocomplete="on" type="text" tabindex="0" name="username" id="username" placeholder=Email&nbsp;Address></td>
            <td>(email address)</td>
        </tr>
        <tr>
            <td align=right>Password:</td>
            <td><input autocomplete="on" type="password" tabindex="0" name="password" id="password" placeholder=Password></td>
            <td><button type="submit">Login</button></td>
        </tr>
    </table>
</form>
....


    private static final String FORM_ID = "login-form";
    private static final String USER_ID = "username";
    private static final String PASSWORD_ID = "password";

    
   private static void doLogin() {
        Window.alert("test 1");
    }

    private static native void injectLoginFunction() /*-{
        $wnd.login = function() {
            @booklion.client.login.Login::doLogin()();
        };
    }-*/;


    public void onModuleLoad() {
        injectLoginFunction();  // ok
        TextBox fUsername = TextBox.wrap(DOM.getElementById(USER_ID));
        fUsername.setStyleName("gwt-TextBox");
        PasswordTextBox fPassword = PasswordTextBox.wrap(DOM.getElementById(PASSWORD_ID));
        fPassword.setStyleName("gwt-PasswordTextBox");
        FormPanel fLoginForm = FormPanel.wrap(DOM.getElementById(FORM_ID), false); 
        fLoginForm.setAction("");  //  ok
        fLoginForm.addSubmitHandler(new FormPanel.SubmitHandler() { 

            @Override
            public void onSubmit(FormPanel.SubmitEvent event) {
                Window.alert("test 2");
            }
        });
        fLoginForm.getElement().setAttribute("onsubmit", "login();return false;");
    }


test 1 gets displayed - not test 2.  Firefox and IE offer to save the password.  Chrome and Safari do not.

Sure would appreciate some help.

Thanks.

Blake McBride

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment