React Native Password Input: Mask, Reveal and Autofill
Turn a TextInput into a password field with secureTextEntry, which masks every character and cannot be combined with multiline. Add a Pressable eye button that flips that prop for show and hide. For password managers, set autoComplete="password" on login screens or "new-password" on signup, and the matching iOS textContentType.
| Prop | Login field | Signup field |
|---|---|---|
| secureTextEntry | true (until revealed) | true (until revealed) |
| autoComplete | "password" | "new-password" |
| textContentType (iOS) | "password" | "newPassword" |
| passwordRules (iOS) | not needed | optional rules for generated passwords |
| autoCapitalize | "none" | "none" |
| autoCorrect | false | false |
Updated
Try the field below: type a password, flip the reveal button, and watch the meter react. Switch between login and signup to see which autofill props each screen should carry; the meter logic is the same short function you can paste into your app.
Password field preview
Strength: empty
Password field code
PasswordInput with a reveal button
Pass isNew for signup screens. The button label always describes what the next press will do.
import { useState } from "react";
import { Pressable, StyleSheet, Text, TextInput, View } from "react-native";
export function PasswordInput({ value, onChangeText, isNew = false }) {
const [hidden, setHidden] = useState(true);
return (
<View style={s.wrap}>
<TextInput
value={value}
onChangeText={onChangeText}
secureTextEntry={hidden}
autoComplete={isNew ? "new-password" : "password"}
textContentType={isNew ? "newPassword" : "password"}
autoCapitalize="none"
autoCorrect={false}
accessibilityLabel="Password"
style={s.input}
/>
<Pressable
accessibilityRole="button"
accessibilityLabel={hidden ? "Show password" : "Hide password"}
hitSlop={8}
onPress={() => setHidden((h) => !h)}
style={s.toggle}
>
<Text>{hidden ? "Show" : "Hide"}</Text>
</Pressable>
</View>
);
}
const s = StyleSheet.create({
wrap: { flexDirection: "row", alignItems: "center", borderWidth: 1, borderColor: "#cbd5e1", borderRadius: 8 },
input: { flex: 1, padding: 12 },
toggle: { paddingHorizontal: 12, paddingVertical: 8 },
});Strength score function
Returns 1 to 4 for any non-empty string. Map the number to a label and a bar width.
export function passwordScore(pw) {
if (!pw) return 0;
const kinds = [/[a-z]/, /[A-Z]/, /[0-9]/, /[^A-Za-z0-9]/].filter((r) => r.test(pw)).length;
let score = 0;
if (pw.length >= 8) score++;
if (pw.length >= 12) score++;
if (pw.length >= 16) score++;
if (kinds >= 3) score++;
if (pw.length < 8) score = Math.min(score, 1);
return Math.min(4, Math.max(score, 1));
}
Autofill on both platforms
autoComplete is the hint both platforms read, while textContentType is iOS only and connects the field to the device keychain. Setting both costs nothing and covers more password managers.
Pair the password field with a username or email field that carries autoComplete="username" or "email", so the manager knows which account the password belongs to.
What the strength meter measures
The meter on this page counts length and the kinds of characters used: lower case, upper case, digits and symbols. It is a quick nudge, not an audit, and it cannot spot a password that is common or already leaked.
Long passphrases score well here, because three of the four points come from length and only one from mixing character types. Pair the meter with a minimum length check in your validation.
How it works
- A boolean in state, hidden, starts as true and feeds secureTextEntry.
- The eye Pressable sits beside the field and flips hidden on each press.
- Its accessibilityLabel switches between Show password and Hide password so the action is always clear.
- The strength function scores length and character variety and returns a label for the bar under the field.
Tips
- Turn off autoCorrect and set autoCapitalize to none, so the keyboard never rewrites a password.
- Use new-password on signup and reset screens; it tells the system to offer a generated password instead of a saved one.
- Keep the reveal button big enough to tap and outside the text area, so it never covers the last characters.
- Treat any client-side meter as a hint only. Length matters most, and the server decides what it accepts.
- Never log the field's value or send it to analytics while debugging.
Frequently asked questions
How do I hide a password in React Native?
Set secureTextEntry on the TextInput. The docs say it obscures the text so passwords stay secure, defaults to false, and does not work with multiline set to true.
How do I add a show password button?
Keep a hidden boolean in state, pass it to secureTextEntry, and render a Pressable next to the field that toggles it. Label the button so screen readers announce what pressing it will do.
Why does iOS not offer a strong password on signup?
Set textContentType="newPassword" on the field. With that value you can also pass passwordRules, written in Apple's password rules syntax, so the generated password meets your requirements.
Which autoComplete value should a password field use?
"password" where someone types an existing password and "new-password" where they create one. Both are listed among the cross-platform autoComplete values.
Related: Password strength checker, React Native TextInput props, React Native forms, Password reset email template, React vs React Native.
Build your site free or see all free tools. On We.Inc you can build your site free, with no card and no trial needed to start. AI building is on paid plans from $19 a month.
More in Guides
- React Native Radio Buttons, Built From Pressable
- React Native TextInput Props, Searchable
- React memo, useMemo and useCallback (with Refs, Portals and useId)
- React Router Examples (v7)
- React Server Components Explained
- React Data Table Examples with TanStack Table
- React with TypeScript: The Types You Actually Need
- React UI Component Libraries Compared: shadcn/ui, Radix, Headless UI, daisyUI, Flowbite and MUI | How-to Guide
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App