Hide password with ••••••• in a textField
You can achieve this directly in Xcode:
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 of0
indicates that you wish to see the text as it is typed, similar to the behavior of a standardJTextField
.
Tutorial and Reference:
- How to use Password Fields
- 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
Swift Covariant Generic Function:Placeholder Type Is a Subclass of Another
Pickers Are Overlapping in iOS 15 Preventing Some of Them to Be Scrolled
Nsimage Getting Resized When I Draw Text on It
Swift 2 to 3 Migration Dispatch_Get_Global_Queue
How to Convert Uint16 to Uint8 in Swift 3
Swiftui Label Text and Image Vertically Misaligned
Swift: Programmatically Enumerate Outgoing Segues from a Uiviewcontroller
Scenekit - Custom Geometry Does Not Show Up
Declare Array of Classes That Conform to a Protocol
Why Does the Following Code Crash on an iPhone 5 But Not an iPhone 5S
Accessor Gives the Wrong Value in Swift 1.2/2.0 Release Build Only
Core Data Predicate Not Working
How to Call the More Specific Method of Overloading
How to Build a Swift Package for iOS Over Command Line
How to Reset Intent Extension Configurations in Widgetkit
Adding Swift 3 Packages to Xcode 8 Using the Swift Package Manager