---
sidebar_position: 0
---

# security

The `sos.management.security` API groups together methods for the management of a security PIN code of the device.

## Methods

### generateRandomPinCode()

The `generateRandomPinCode()` generates a random 4-digit PIN code and sets it as the current PIN code.

```ts expandable
generateRandomPinCode(): Promise<void>;
```

#### Return value

A promise that resolves when the random PIN code is successfully set.

#### Example

```ts
await sos.management.security.generateRandomPinCode(); // Generate new random PIN code
const newPinCode = await sos.management.security.getPinCode(); // Get PIN code as string
console.log(newPinCode);
```

<Separator />

### getPinCode()

The `getPinCode()` method returns the currently set PIN code.

```ts expandable
getPinCode(): Promise<string>;
```

#### Return value

A promise that resolves to the currently set PIN code.

#### Possible errors

Get PIN code failed because the PIN code has not been set yet.

#### Example

```ts
const pinCode = await sos.management.security.getPinCode();
console.log(`Current PIN code is: ${pinCode}`);
```

<Separator />

### setPinCode()

The `setPinCode()` method sets the pin code.

:::warning
The maximum length of the PIN code is four characters.
:::

```ts expandable
setPinCode(pinCode: string): Promise<void>;
```

#### Params

| Name      | Type     | Required         | Description             |
|-----------|----------|------------------|-------------------------|
| `pinCode` | `string` |  <div>Yes</div>  | The PIN code to be set. |

#### Return value

A promise that resolves when the PIN code is successfully set.

#### Possible errors


- Invalid PIN code format.
- PIN code 0000 is not allowed, use another PIN code.

#### Example

```ts
await sos.management.security.setPinCode("9999");
```

:::note[GitHub Example]

- [ Applet Example with PIN setup](https://github.com/signageos/applet-examples/tree/master/examples/management-js-api/security-pin-code)

:::