---
name: "addPassword"
mode: "api"
versionRequirements:
  - { name: "@ray-js/lock-sdk", version: "1.0.0" }
title: "addPassword - Add unlock password."
summary: "Add unlock password."
---

## addPassword

> [VERSION] @ray-js/lock-sdk >= 1.0.0

### Description

Add a password-type unlock method.

### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `password` | `string` | Yes | Password content |
| `userId` | `string` | Yes | User ID |
| `name` | `string` | Yes | Unlock method name |
| `isSpecial` | `boolean` | No | Whether it's a special unlock method |
| `specialInfo` | `SpecialUnlockMethodInfo` | No | Special unlock method configuration |

##### SpecialUnlockMethodInfo properties

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `appSend` | `boolean` | No | - | Whether App notifications are supported |
| `msgSend` | `boolean` | No | - | Whether SMS notifications are supported |
| `msgPhone` | `string` | No | - | SMS notification phone number |
| `verifyCode` | `string` | No | - | SMS verification code |
| `countryCode` | `string` | No | - | SMS notification country code |


### Return Value

Type: `Promise<CreateUnlockMethodResult>`

None (resolves after added successfully)

##### CreateUnlockMethodResult

| Property | Type | Description |
| --- | --- | --- |
| `opModeId` | `number` | Unlock method ID |
| `unlockName` | `string` | Unlock method name |

### Error Codes

| Error Code | Error Message |
| --- | --- |
| `1054` | Password is empty |
| `1057` | Special password not supported and App notifications are disabled |
| `1058` | SMS is supported, but both App notifications and SMS are disabled |
| `1066` | SMS phone number is empty |
| `1056` | Country code is empty |
| `1055` | Verification code is empty |
| `1014` | This unlock method type is not supported |
| `1001` | Device is offline |
| `1002` | Operation timed out |
| `1015` | ~1025 Device-reported add failure (status 0~10) |
| `1026` | Device-reported add failure (status 0xfe) |
| `1037` | Cloud: password already exists (USER_PWD_ALREADY_EXIST) |
| `1038` | Cloud: password name is duplicate (LOCK_PWD_NAME_REPEAT) |
| `1040` | Cloud: record does not exist (RECORD_NOT_EXIST) |

### Examples

#### Example

```ts
import { addPassword } from '@ray-js/lock-sdk';
await addPassword({ password: '123456', userId: 'user_001', name: 'Daily password' });
```
