219

I have a TextInput. Instead of showing the actual text entered, when the user enters text I want it to show the password dots / asterisks (****) you typically see in apps when typing a password. How can I do this?

<TextInput
  style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
  onChangeText={(text) => this.setState({input: text})}
/>
1
  • I am using 0.56RC secureTextEntry={true} Along with password={true} then only its working as mentioned by @NicholasByDesign
    – Ramusesan
    Commented Jun 28, 2018 at 5:12

15 Answers 15

570

When this was asked there wasn't a way to do it natively, however this will be added on the next sync according to this pull request. Here is the last comment on the pull request - "Landed internally, will be out on the next sync"

When it is added you will be able to do something like this

<TextInput secureTextEntry={true} style={styles.default} value="abc" />

refs

4
  • 1
    thanks, so until that gets merged, what other options are there? I'm guessing facebook does something similar for logins to their own apps.
    – bwbrowning
    Commented Mar 30, 2015 at 2:33
  • 2
    I was looking into it today, that is how I found that pull request. They say they only have 2 apps that are 100% React Native. The F8 app it opens a new window asking for authorization. Facebook Ads has the functionality that we are looking for, but I almost think they wrapped Objective-C for it. Another way to do it would be to store the string and every time the input updates replace the last character with the ... stuff :). Commented Mar 30, 2015 at 2:46
  • 1
    @bwbrowning, it should be merged soon; long before you deploy I'd wager.
    – Brigand
    Commented Mar 30, 2015 at 3:24
  • keyboardType={'phone-pad'} if this is set then also it will not work. Commented Nov 18, 2021 at 4:28
56

May 2018 react-native version 0.55.2

This works fine:

secureTextEntry={true}

And this does not work anymore:

password={true} 
0
27

Just add the line below to the <TextInput>

secureTextEntry={true}
18

Add

secureTextEntry={true}

or just

secureTextEntry 

property in your TextInput.

Working Example:

<TextInput style={styles.input}
           placeholder="Password"
           placeholderTextColor="#9a73ef"
           returnKeyType='go'
           secureTextEntry
           autoCorrect={false}
/>
1
  • 4
    Bonus for turning off autocorrect. Commented May 13, 2022 at 14:42
13

You need to set a secureTextEntry prop to true and for better user experience you can use an eye icon to show the actual password

 import {TextInput, Card} from 'react-native-paper';
 const [hidePass, setHidePass] = useState(true);

 const [password, setPassword] = useState('');


<TextInput
            
            label="Password"
            outlineColor="black"
            activeOutlineColor="#326A81"
            autoCapitalize="none"
            returnKeyType="next"
            mode="outlined"
            secureTextEntry={hidePass ? true : false}
            selectionColor="#326A81"
            blurOnSubmit={false}
            onChangeText={password => updateState({password})}
            right={
              <TextInput.Icon
                name="eye"
                onPress={() => setHidePass(!hidePass)}
              />
            }
          />
2
  • It opens/closes keyboard on clicking eye button? Poor experience Commented Oct 24, 2023 at 16:55
  • <TextInput.Icon icon="eye' onPress={/* show / hide stuff */} /> the props name is now icon.
    – Bruce Lee
    Commented yesterday
7

I had to add:

secureTextEntry={true}

Along with

password={true}

As of 0.55

1
  • 3
    you do not need password={true}
    – KetZoomer
    Commented Sep 4, 2020 at 22:55
6

An TextInput must include secureTextEntry={true}, note that the docs of React state that you must not use multiline={true} at the same time, as that combination is not supported.

You can also set textContentType={'password'} to allow the field to retrieve credentials from the keychain stored on your mobile, an alternative way to enter credentials if you got biometric input on your mobile to quickly insert credentials. Such as FaceId on iPhone X or fingerprint touch input on other iPhone models and Android.

 <TextInput value={this.state.password} textContentType={'password'} multiline={false} secureTextEntry={true} onChangeText={(text) => { this._savePassword(text); this.setState({ password: text }); }} style={styles.input} placeholder='Github password' />
6

A little plus:

version = RN 0.57.7

secureTextEntry={true}

does not work when the keyboardType was "phone-pad" or "email-address"

0
5

 <TextInput
        placeholder="Password"
        secureTextEntry={true}
        style={styles.input}
        onChangeText={setPassword}
        value={password}
      />

4

If you added secureTextEntry={true} but did not work then check the multiline={true} prop, because if it is true, secureTextEntry does not work.

4
<TextInput
  placeholderTextColor={colors.Greydark}
  placeholder={'Enter Password'}
  secureTextEntry={true} />
0
4

You need to set a secureTextEntry prop to true

<TextInput
  placeholder="Re-enter password"
  style={styles.input}
  secureTextEntry={true}
  value={confirmPsw}
  onChangeText={setconfirmPsw}
/>
3

You can get the example and sample code at the official site, as following:

<TextInput password={true} style={styles.default} value="abc" />

Reference: http://facebook.github.io/react-native/docs/textinput.html

2
  • 2
    Yes, I saw this as well. But for me it is only working with secureTextEntry={true} .
    – namxam
    Commented Jun 30, 2015 at 11:51
  • Just upgrade to latest stable(0.8.0) and password={true} will work. Commented Jul 11, 2015 at 17:23
1
<TextInput 
   secureTextEntry 
   placeholder="password" placeholderTextColor="#297542" 
   autoCorrect={false} style={mystyles.inputStylee} 
/>

You can simply add the secureTextEntry prop to TextInput and omit its value. By default, it is set to true. To make it to false do this secureTextEntry={false}

1
  • 1
    While perfectly correct, I'd recommend setting it explicitely to {true} so one does not have to rely on remembering what's the default for that property Commented Oct 3, 2021 at 12:51
0
const [password, setPassword] = useState('');  
const [passwordVisibility, setPasswordVisibility] = useState(true);  
const [rightIcon, setRightIcon] = useState('eye');  
const [rightIconColor, setRightIconColor] = useState('#0C8A7B');

 const handlePasswordVisibility = () => {  
        if (rightIcon === 'eye') {  
            setRightIcon('eye-slash');  
            //setRightIconColor('#FF0000')  
            setPasswordVisibility(!passwordVisibility);  
        } else if (rightIcon === 'eye-slash') {  
            setRightIcon('eye');  
            //setRightIconColor('#0C8A7B')
            setPasswordVisibility(!passwordVisibility);  
        }  
    };  
 <TextInput  
     style={{
        height: 45,  
        margin: 12,  
        padding: 10,  
        backgroundColor: 'white',  
        borderRadius: 10  
    }}  
   name="password"  
   placeholder="Enter password"  
   autoCapitalize="none"  
   autoCorrect={false}  
   secureTextEntry={passwordVisibility}  
   value={password}  
   enablesReturnKeyAutomatically  
   onChangeText={text => setPassword(text)}  
  />

  <TouchableOpacity
      onPress={handlePasswordVisibility}>
  <Icon name={rightIcon} size={25} color={rightIconColor} />
  </TouchableOpacity>
</View>


**I Hope this will help you**
1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Dec 20, 2022 at 3:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.