# PasswordField

> Makes a text field where the user can enter a password.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.7/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

## PasswordField(Rect, string, GUIStyle)

Makes a text field where the user can enter a password.

```csharp
public static string PasswordField(Rect position, string password, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the password field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The password to edit.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): Optional [GUIStyle](/engine/6000.7/script-reference/unityengine/guistyle.md).

### Returns

| Type                                                           | Description                       |
| -------------------------------------------------------------- | --------------------------------- |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The password entered by the user. |

### Remarks

This works just like [GUI.PasswordField](/engine/6000.7/script-reference/unityengine/gui/passwordfield.md), but correctly responds to select all, etc. in the editor, and it can have an optional label in front.

![EditorGUIPasswordField (PasswordField)](/api/media?file=/engine/6000.7/media/images/EditorGUIPasswordField.png)

*Password Field in an Editor Window.*

### Examples

```csharp
using UnityEngine;
using UnityEditor;

// Editor Script that creates a password field and lets you visualize what have you
// typed in a label.

class EditorGUIPasswordField : EditorWindow
{
    string text = "Some text here";

    [MenuItem("Examples/Editor Password field usage")]
    static void Init()
    {
        EditorWindow window = GetWindow<EditorGUIPasswordField>();
        window.Show();
    }

    void OnGUI()
    {
        text = EditorGUI.PasswordField(
            new Rect(3, 3, position.width - 6, 20),
            "Type Something:",
            text);

        EditorGUI.LabelField(
            new Rect(3, 25, position.width - 5, 20),
            "Written Text:",
            text);
    }
}
```

## PasswordField(Rect, string, string, GUIStyle)

Makes a text field where the user can enter a password.

```csharp
public static string PasswordField(Rect position, string label, string password, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the password field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional label to display in front of the password field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The password to edit.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): Optional [GUIStyle](/engine/6000.7/script-reference/unityengine/guistyle.md).

### Returns

| Type                                                           | Description                       |
| -------------------------------------------------------------- | --------------------------------- |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The password entered by the user. |

### Remarks

This works just like [GUI.PasswordField](/engine/6000.7/script-reference/unityengine/gui/passwordfield.md), but correctly responds to select all, etc. in the editor, and it can have an optional label in front.

![EditorGUIPasswordField (PasswordField)](/api/media?file=/engine/6000.7/media/images/EditorGUIPasswordField.png)

*Password Field in an Editor Window.*

### Examples

```csharp
using UnityEngine;
using UnityEditor;

// Editor Script that creates a password field and lets you visualize what have you
// typed in a label.

class EditorGUIPasswordField : EditorWindow
{
    string text = "Some text here";

    [MenuItem("Examples/Editor Password field usage")]
    static void Init()
    {
        EditorWindow window = GetWindow<EditorGUIPasswordField>();
        window.Show();
    }

    void OnGUI()
    {
        text = EditorGUI.PasswordField(
            new Rect(3, 3, position.width - 6, 20),
            "Type Something:",
            text);

        EditorGUI.LabelField(
            new Rect(3, 25, position.width - 5, 20),
            "Written Text:",
            text);
    }
}
```

## PasswordField(Rect, GUIContent, string, GUIStyle)

Makes a text field where the user can enter a password.

```csharp
public static string PasswordField(Rect position, GUIContent label, string password, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the password field.**** (\[GUIContent]\(/engine/6000.7/script-reference/unityengine/guicontent)): Optional label to display in front of the password field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The password to edit.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): Optional [GUIStyle](/engine/6000.7/script-reference/unityengine/guistyle.md).

### Returns

| Type                                                           | Description                       |
| -------------------------------------------------------------- | --------------------------------- |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The password entered by the user. |

### Remarks

This works just like [GUI.PasswordField](/engine/6000.7/script-reference/unityengine/gui/passwordfield.md), but correctly responds to select all, etc. in the editor, and it can have an optional label in front.

![EditorGUIPasswordField (PasswordField)](/api/media?file=/engine/6000.7/media/images/EditorGUIPasswordField.png)

*Password Field in an Editor Window.*

### Examples

```csharp
using UnityEngine;
using UnityEditor;

// Editor Script that creates a password field and lets you visualize what have you
// typed in a label.

class EditorGUIPasswordField : EditorWindow
{
    string text = "Some text here";

    [MenuItem("Examples/Editor Password field usage")]
    static void Init()
    {
        EditorWindow window = GetWindow<EditorGUIPasswordField>();
        window.Show();
    }

    void OnGUI()
    {
        text = EditorGUI.PasswordField(
            new Rect(3, 3, position.width - 6, 20),
            "Type Something:",
            text);

        EditorGUI.LabelField(
            new Rect(3, 25, position.width - 5, 20),
            "Written Text:",
            text);
    }
}
```
