What's new

Help Java how to cencor user input and detect special character on a string

Nero Swallowtail

Eternal Poster
Joined
Aug 13, 2020
Posts
465
Reaction
174
Points
280
guys help! paano po ba ung ganon? ung pag ka nag i input is user sa mismong scanner e napapalitan ng asterisk ung iniinput nya sa mismong scanner? or kahit kapag dun nalang sa mismong compiler, kapag prinint ung inenter na password e magiging asterisk lahat? tsaka kung pano na din gagawa ng User Defined Exception kapag ka my Special character na naka sulat, kahit formatting nalang po ibigay nyo, wala po kase sa handout hehehehe ty
 
Replace lahat ng asterisk yung input ng user? i.e. userInput = "PHC" then output ay "***".
 
try mo nga to
char[] password = console.readPassword("Enter password");
Arrays.fill(password, ' ');
 
[CODE title="baka makatulong"]public class Test {

public static void main(final String[] args) throws Exception {
ConsoleReader reader = new ConsoleReader();
Character mask = '*';
String line = null;
do {
line = reader.readLine("Enter Password(blank pwd to exit)> ", mask);
System.out.println("Got password: " + line);
} while (line != null && line.length() > 0);
}

}[/CODE]
 
[XX='Nero Swallowtail, c: 1117526, m: 1752019'][/XX] Next time be precise and specific on your thread titles, sabi mo din kase Java sa thread title mo eh misleading ka tuloy.
 
[XX='Nero Swallowtail, c: 1117527, m: 1752019'][/XX] e bat java nakalagay sa title mo. be precise next time.
 
[XX='PHC rem, c: 1117733, m: 765534'][/XX] ay sorry, scanner ba yung "console?" sanay kase ako na scan lang pinapangalang sa scanner ko hehe
 
[XX='PHC rem, c: 1117733, m: 765534'][/XX] diba kase sa c# my Console.Readkey akala ko ung Console.readPassword parang other scanner sa c# e HAHAHA
 
[XX='Nero Swallowtail, c: 1118452, m: 1752019'][/XX] may mga similarities din kasi yong java at c# minsan nalilito din ako.
 
JAVA:
set mo lang yung echoCharacter ng jPasswordField ng ganito:
jPasswordField.setEchoChar((char)0) - Makikita mo yung characters sa textfield.
jPasswordField.setEchoChar('\u50cf') - Magiging small squares yung characters sa textfield. Palitan mo lang yung '\u50cf' sa kung anong gusto mong character. Yung * yata ay '\u20cf'. di ko lang sure.😁😁
 
Last edited:
Back
Top