简体   繁体   中英

Partial Display of email id in JSP. (Password Reset)

Present Scenario

when a user tries to reset his password,

Enter account number and submit. (ex:123456789)

(account number contains email in DB).

then displays "Instructions to reset your password have been emailed to the address on file for account number :123456789".

So am trying to Display a Partial emailID to user.

like "Instructions to reset your password have been emailed to "Jo******pa@gmail.com" for account number :123456789".

At present what i done is.

In Action class: (ResetPasswordAction.java)
String email =**retriving email id**
at end 
request.setAttribute("email", email);
before forwarding.


In Jsp (Display after email sent)
<c:out value="${email}"/> 

Worked fine.

Now my question:

1) Is this the correct approach.

2) * How to replace String (email) with stars ** like "Jo* * **pa@gmail.com" . am trying, but is there any simple way. *Java 1.4

Added:

  String Str = "John.smithpa@gmail.com";
  String S=Str.replaceFirst("@(.*)","" );
  String mail=Str.replaceFirst("(.*)@","" );
  String trim=S.substring(2, S.length()-2);
  String star = trim.replaceAll(".", "*");
  String name= S.replaceAll(trim,star);
  String Disp=name+"@"+mail;
  System.out.println(Disp);

You can use regex like this:

String email="abcdef@xyz.com";
String str=email.replaceAll("(?<=..).(?=...*@)", "*");
System.out.println(str);

Output:

ab**ef@xyz.com

for question 2: what i can think out is use Regex,like follow:

           Pattern p = Pattern.compile("\\w{2}(.*)\\w{2}@.*");
           Matcher m = p.matcher(email);
           if (m.find(0)) {
                String star = m.group(1).replaceAll(".", "*");
                email = email.replace(m.group(1), star);
           }

but you'd make sure the email is in correct format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM