Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Re-displaying secret password asterisks on a two phase login

843844Oct 13 2008 — edited Oct 13 2008
Hi,

I'm trying to amend a login panel to re-display the password asterisks after the authenticate button is pressed.

When the user first enters an id and password the password is displayed as asterisks fine. After clicking 'authenticate' the password appears to the user as if it is reset to blank. What I would to happen is that the asterisks representing the password to appear after 'authenticate' is clicked. Trying to set the password field does not seem to work and looking around the web and in books at login page examples, can't seem to find any examples of a two stage login with this behavior.

I would be grateful for any ideas, questions or comments about this you might have.

Best regards,

Mike

login.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<head></head>

<body>

<f:view>
<h:form>

<table>
<tr>
<td><b><h:outputLabel value="Login ID" for="username" disabled="#{loginMBean.authenticateDisabled}"/></b></td>
<td><h:inputText id="username" value="#{loginMBean.username}" disabled="#{loginMBean.authenticateDisabled}"/></td>
<td><h:outputText id="invalidloginid" value="#{loginMBean.invalidLoginid}"/></td>
</tr>
<tr>
<td><b><h:outputLabel value="Password" for="password" disabled="#{loginMBean.authenticateDisabled}"/></b></td>
<td><h:inputSecret id="password" value="#{loginMBean.password}" disabled="#{loginMBean.authenticateDisabled}"/></td>
<td><h:outputText id="invalidpassword" value="#{loginMBean.invalidPassword}"/></td>
</tr>
<tr>
<td></td>
<td>
<h:commandButton value="Authenticate" action="authenticate" actionListener="#{loginMBean.authenticate}" disabled="#{loginMBean.authenticateDisabled}"/>
</td>
</tr>
<tr>
<td><b><h:outputLabel value="Tenant" for="pickTenant" disabled="#{loginMBean.loginDisabled}"/></b></td>
<td>
<h:selectOneListbox id="pickTenant" value="#{loginMBean.currentTenant}" disabled="#{loginMBean.loginDisabled}" size="1">
<f:selectItems value="#{loginMBean.tenantList}" />
</h:selectOneListbox>
</td>
</tr>
<tr>
<td><b><h:outputLabel value="Locale" for="pickLocale" disabled="#{loginMBean.loginDisabled}"/></b></td>
<td>
<h:selectOneListbox id="pickLocale" value="#{loginMBean.currentLocale}" disabled="#{loginMBean.loginDisabled}" size="1">
<f:selectItems value="#{loginMBean.localeList}" />
</h:selectOneListbox>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td></td>
<td><h:commandButton value="Log In" action="#{loginMBean.getHomepage}" actionListener="#{loginMBean.login}" disabled="#{loginMBean.loginDisabled}"/></td>
<td><h:commandButton value="Reset" action="reset" actionListener="#{loginMBean.reset}" disabled="#{loginMBean.loginDisabled}" immediate="true"/></td>
</tr>
<tr>
<td></td>
<td>
<h:messages globalOnly="false"/>
</td>
</tr>
</table>


</h:form>
</f:view>

</div>

</body>
</html>
faces-config.xml entry
<managed-bean>
<managed-bean-name>loginMBean</managed-bean-name>
<managed-bean-class>com.mycompany.ui.login.managedbeans.LoginMBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
Managed bean
package com.mycompany.ui.login.managedbeans;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;

public class LoginMBean {

private String username;
private String password;
private Date logintime;
private String displayname;
private String homepage;

private boolean authenticateEnabled=true;

private List<SelectItem> tenantList=new ArrayList<SelectItem>();
private String currentTenant;
private List<SelectItem> localeList=new ArrayList<SelectItem>();
private String currentLocale;

private String invalidLoginid;
private String invalidPassword;

public String getInvalidLoginid() {
return invalidLoginid;
}
public void setInvalidLoginid(String invalidLoginid) {
this.invalidLoginid = invalidLoginid;
}
public String getInvalidPassword() {
return invalidPassword;
}
public void setInvalidPassword(String invalidPassword) {
this.invalidPassword = invalidPassword;
}

public LoginMBean() {
tenantList.add(new SelectItem("Client1","Client1"));

currentTenant="";
localeList.add(new SelectItem("en_GB","English"));
currentLocale="";
}

public String getDisplayname() {
return displayname;
}
public void setDisplayname(String displayname) {
this.displayname = displayname;
}

public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}

public void authenticate(ActionEvent ae) {
boolean error=false;

this.invalidLoginid="";
this.invalidPassword="";

if ((username==null)||(username.equalsIgnoreCase(""))) {
this.invalidLoginid="Invalid login id";
error=true;
}
if ((password==null)||(password.equalsIgnoreCase(""))) {
this.invalidPassword="Invalid password";
error=true;
}
if (error) return;

this.currentLocale="";
this.currentTenant="";

this.displayname=username;

this.authenticateEnabled=false;
}

public void login(ActionEvent ae) {
if (username.startsWith("admin"))
this.homepage="administrator";
else
this.homepage="clerk";

reset();

setLogintime(new Date());
}

private void reset() {
this.username="";
this.password="";
this.invalidLoginid="";
this.invalidPassword="";

this.authenticateEnabled=true;
}

public void reset(ActionEvent ae) {
reset();
}

public boolean getAuthenticateDisabled() {
return !authenticateEnabled;
}
public boolean getLoginDisabled() {
return authenticateEnabled;
}


private String about;
private String help;
private String notimplemented;
private String loggedintext;
private String returntologinpanel;
private String logout;

private void setEnglishLiterals() {
this.about="About";
this.help="Help";
}

public String getAbout() {
return about;
}
public String getHelp() {
return help;
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 10 2008
Added on Oct 13 2008
3 comments
494 views