# OpcServerIdentity Members

> Reference: Represents the identity of a user of the server, which is identified by a user name and a password.

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">OpcServerIdentity</a></dd>
<dt>Namespace</dt>
<dd><a href="../namespaces/opc.uafx.server">Opc.UaFx.Server</a></dd>
<dt>Assembly</dt>
<dd>Opc.UaFx.Advanced.dll</dd>
<dt>Package</dt>
<dd>Opc.UaFx.Advanced v2.59.0</dd>
</dl>

Inherits members from [OpcUserIdentity](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcuseridentity/members), [OpcIdentity](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcidentity/members).

## Constructors

### OpcServerIdentity

<span class="api-meta">3 overloads</span>

| Overload | Description |
|---|---|
| [OpcServerIdentity(string)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/members#opcserveridentity-system-string)<span class="api-meta">since v2.7</span> | Initializes a new instance of the [OpcServerIdentity](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/) class using the `userName` specified and an empty password. |
| [OpcServerIdentity(string, string)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/members#opcserveridentity-system-string-system-string)<span class="api-meta">since v2.7</span> | Initializes a new instance of the [OpcServerIdentity](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/) class using the `userName` and `password` specified. |
| [OpcServerIdentity(string, byte\[\])](#opcserveridentity-system-string-system-byte-array) | Initializes a new instance of the [OpcServerIdentity](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/) class using the `userName` and `password` specified. |

**Exceptions (all overloads)**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The `userName` is equals [Empty](https://learn.microsoft.com/dotnet/api/system.string.empty). |

#### OpcServerIdentity(string)

<span class="api-meta">since v2.7</span>

Initializes a new instance of the [OpcServerIdentity](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/) class using the `userName` specified and an empty password.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcServerIdentity(string userName)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(userName As String)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `userName` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The name of the user. |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `userName` is a null reference (Nothing in Visual Basic). |

#### OpcServerIdentity(string, string)

<span class="api-meta">since v2.7</span>

Initializes a new instance of the [OpcServerIdentity](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/) class using the `userName` and `password` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcServerIdentity(string userName, string password)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(userName As String, password As String)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `userName` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The name of the user. |
| `password` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The password of the user, which is stored as transformed by [TransformPassword](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/members#transformpassword). |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `userName` or `password` is a null reference (Nothing in Visual Basic). |

**Remarks**

The constructor calls the virtual method [TransformPassword](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/members#transformpassword), so that an override in a derived class is called before the constructor of the derived class has initialized the instance.

#### OpcServerIdentity(string, byte\[\])

Initializes a new instance of the [OpcServerIdentity](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/) class using the `userName` and `password` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcServerIdentity(string userName, byte[] password)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(userName As String, password As Byte())
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `userName` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The name of the user. |
| `password` | [Byte](https://learn.microsoft.com/dotnet/api/system.byte)[] | The bytes of the password of the user, which need to equal the result of [TransformPassword](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/members#transformpassword) for the password a client provides; by default these are the bytes of the password encoded using UTF-16 (little endian). |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `userName` or `password` is a null reference (Nothing in Visual Basic). |

**Remarks**

The `password` is stored without being copied, so that later changes of the array change the password of the identity.

## Properties

### DisplayName

<span class="api-meta">override</span>

Gets the name displayed for the identity.

<div class="api-signature" data-lang="csharp">

```csharp
public override string DisplayName { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides ReadOnly Property DisplayName As String
```

</div>

**Property value**

[String](https://learn.microsoft.com/dotnet/api/system.string)

The [UserName](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/members#username) of the identity.

**Overrides**

[DisplayName](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcuseridentity/members#displayname)

### UserName

Gets the name of the user.

<div class="api-signature" data-lang="csharp">

```csharp
public string UserName { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property UserName As String
```

</div>

**Property value**

[String](https://learn.microsoft.com/dotnet/api/system.string)

The user name specified on construction.

## Methods

### ChangePassword

<span class="api-meta">2 overloads</span>

| Overload | Description |
|---|---|
| [ChangePassword(string)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/members#changepassword-system-string)<span class="api-meta">since v2.7</span> | Changes the password of the identity to the `password` specified. |
| [ChangePassword(byte\[\])](#changepassword-system-byte-array) | Changes the password of the identity to the bytes specified by `password`. |

**Exceptions (all overloads)**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `password` is a null reference (Nothing in Visual Basic). |

#### ChangePassword(string)

<span class="api-meta">since v2.7</span>

Changes the password of the identity to the `password` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public void ChangePassword(string password)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub ChangePassword(password As String)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `password` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The new password of the user, which is stored as transformed by [TransformPassword](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/members#transformpassword). |

#### ChangePassword(byte\[\])

Changes the password of the identity to the bytes specified by `password`.

<div class="api-signature" data-lang="csharp">

```csharp
public void ChangePassword(byte[] password)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub ChangePassword(password As Byte())
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `password` | [Byte](https://learn.microsoft.com/dotnet/api/system.byte)[] | The bytes of the new password of the user, which need to equal the result of [TransformPassword](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/members#transformpassword) for the password a client provides; by default these are the bytes of the password encoded using UTF-16 (little endian). |

**Remarks**

The bytes are copied.

### Impersonate

<span class="api-meta">override</span>

Returns an impersonation context for the identity.

<div class="api-signature" data-lang="csharp">

```csharp
public override OpcImpersonationContext Impersonate()
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overrides Function Impersonate() As OpcImpersonationContext
```

</div>

**Returns**

[OpcImpersonationContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcimpersonationcontext/)

An instance of the [OpcDefaultImpersonationContext](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdefaultimpersonationcontext/) class, which does not impersonate the user.

**Overrides**

[Impersonate](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcuseridentity/members#impersonate)

### Matches

<span class="api-meta">virtual · since v2.7</span>

Determines whether the `userName` and `password` specified match the identity.

<div class="api-signature" data-lang="csharp">

```csharp
public virtual bool Matches(string userName, string password)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Overridable Function Matches(
    userName As String,
    password As String) As Boolean
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `userName` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The user name to compare. |
| `password` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The password to compare. |

**Returns**

[Boolean](https://learn.microsoft.com/dotnet/api/system.boolean)

The value true if the `userName` equals the [UserName](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/members#username) (case-sensitive) and the result of [TransformPassword](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/members#transformpassword) for the `password` equals the password of the identity; otherwise the value false.

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The `userName` is equals [Empty](https://learn.microsoft.com/dotnet/api/system.string.empty). |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `userName` or `password` is a null reference (Nothing in Visual Basic). |

**Remarks**

The passwords are compared in constant time.

### TransformPassword

<span class="api-meta">protected · virtual · since v2.7</span>

Transforms the `password` specified into the bytes stored and compared by the identity.

<div class="api-signature" data-lang="csharp">

```csharp
protected virtual byte[] TransformPassword(string password)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Protected Overridable Function TransformPassword(password As String) As Byte()
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `password` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The password to transform. |

**Returns**

[Byte](https://learn.microsoft.com/dotnet/api/system.byte)[]

The bytes of the `password`. The base implementation returns the password encoded using UTF-16 (little endian) (see [Unicode](https://learn.microsoft.com/dotnet/api/system.text.encoding.unicode)).

**Remarks**

The method is also called by the constructor [OpcServerIdentity](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.server.opcserveridentity/members#opcserveridentity-system-string-system-string).
