Hide Password with "•••••••" in a Textfield

Hide password with ••••••• in a textField

You can achieve this directly in Xcode:

Sample Image

The very last checkbox, make sure secure is checked .

Or you can do it using code:

Identifies whether the text object should hide the text being entered.

Declaration

optional var secureTextEntry: Bool { get set }

Discussion

This property is set to false by default. Setting this property to true creates a password-style text object, which hides the text being entered.

example:

texfield.secureTextEntry = true

How to show/hide password in TextFormField?

First make you widget StatefulWidget if it is a StatelessWidget.

Then have a variable bool _obscureText and pass it to your TextFormField. The toggle it with setState as required.

Example:

class _FormFieldSampleState extends State<FormFieldSample> {

// Initially password is obscure
bool _obscureText = true;

String _password;

// Toggles the password show status
void _toggle() {
setState(() {
_obscureText = !_obscureText;
});
}

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Sample"),
),
body: new Container(
child: new Column(
children: <Widget>[
new TextFormField(
decoration: const InputDecoration(
labelText: 'Password',
icon: const Padding(
padding: const EdgeInsets.only(top: 15.0),
child: const Icon(Icons.lock))),
validator: (val) => val.length < 6 ? 'Password too short.' : null,
onSaved: (val) => _password = val,
obscureText: _obscureText,
),
new FlatButton(
onPressed: _toggle,
child: new Text(_obscureText ? "Show" : "Hide"))
],
),
),
);
}
}

Hope this helps!

How to toggle a UITextField secure text entry (hide password) in Swift?

Use this code,

iconClick is bool variable, or you need other condition check it,

var iconClick = true

eye Action method:

@IBAction func iconAction(sender: AnyObject) {
if(iconClick == true) {
passwordTF.secureTextEntry = false
} else {
passwordTF.secureTextEntry = true
}

iconClick = !iconClick
}

hope its helpful

Toggle password field jetpack compose

Check this:

    var passwordVisibility: Boolean by remember { mutableStateOf(false) }
TextField(value = "Enter Password",
visualTransformation = if (passwordVisibility) VisualTransformation.None else PasswordVisualTransformation(),
leadingIcon = {
IconButton(onClick = {
passwordVisibility = !passwordVisibility
}) {
Icon(imageVector = vectorResource(id = R.drawable.ic_icons_watch_count_24))
}
},
onValueChange = { })

Hide/Show Password in a JTextFIeld (Java Swing)


How exactly do I mask the user input with asterisks preserving its original value?

Use the JPasswordField which has nice function jPasswordField.getPassword(); to get the password as char[] to work with.

  • Use jPasswordField1.setEchoChar('*') to mask the password characters with *.
  • If you wish to see the value you are inserting use jPasswordField1.setEchoChar((char)0); Setting a value of 0 indicates that you wish to see the text as it is typed, similar to the behavior of a standard JTextField.

Tutorial and Reference:

  1. How to use Password Fields
  2. setEchoChar(char)

Password show/hide toggle deletes password TextField value (Flutter)

When you use the setState to toggle the visibility, the build method will get called to redraw that widget. Since you are initialising your TextEditingController in the build method, it get initialised again and loose the previous value. To fix this you just remove the initialisation from build method to class level.

class _LoginScreenState extends State<LoginScreen> {
bool _showPassword = true;
final usernameController = TextEditingController();
final passwordController = TextEditingController();

@override
Widget build(BuildContext context) {

return SafeArea(
//... Your code
);
}
//... Your code
}


Related Topics



Leave a reply



Submit