# PasswordField

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

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.IMGUIModule

## PasswordField(Rect, string, char)

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

```csharp
public static string PasswordField(Rect position, string password, char maskChar)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the text field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Password to edit. The return value of this function should be assigned back to the string as shown in the example.**** (\[char]\(https\://learn.microsoft.com/dotnet/api/system.char)): Character to mask the password with.

### Returns

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

### Examples

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public string passwordToEdit = "My Password";

    void OnGUI()
    {
        passwordToEdit = GUI.PasswordField(new Rect(10, 10, 200, 20), passwordToEdit, "*"[0], 25);
    }
}
```

## PasswordField(Rect, string, char, int)

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

```csharp
public static string PasswordField(Rect position, string password, char maskChar, int maxLength)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the text field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Password to edit. The return value of this function should be assigned back to the string as shown in the example.**** (\[char]\(https\://learn.microsoft.com/dotnet/api/system.char)): Character to mask the password with.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The maximum length of the string. If left out, the user can type for ever and ever.

### Returns

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

### Examples

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public string passwordToEdit = "My Password";

    void OnGUI()
    {
        passwordToEdit = GUI.PasswordField(new Rect(10, 10, 200, 20), passwordToEdit, "*"[0], 25);
    }
}
```

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

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

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

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the text field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Password to edit. The return value of this function should be assigned back to the string as shown in the example.**** (\[char]\(https\://learn.microsoft.com/dotnet/api/system.char)): Character to mask the password with.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): The style to use. If left out, the `textField` style from the current [GUISkin](/engine/6000.7/script-reference/unityengine/guiskin.md) is used.

### Returns

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

### Examples

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public string passwordToEdit = "My Password";

    void OnGUI()
    {
        passwordToEdit = GUI.PasswordField(new Rect(10, 10, 200, 20), passwordToEdit, "*"[0], 25);
    }
}
```

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

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

```csharp
public static string PasswordField(Rect position, string password, char maskChar, int maxLength, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the text field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Password to edit. The return value of this function should be assigned back to the string as shown in the example.**** (\[char]\(https\://learn.microsoft.com/dotnet/api/system.char)): Character to mask the password with.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The maximum length of the string. If left out, the user can type for ever and ever.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): The style to use. If left out, the `textField` style from the current [GUISkin](/engine/6000.7/script-reference/unityengine/guiskin.md) is used.

### Returns

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

### Examples

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public string passwordToEdit = "My Password";

    void OnGUI()
    {
        passwordToEdit = GUI.PasswordField(new Rect(10, 10, 200, 20), passwordToEdit, "*"[0], 25);
    }
}
```
