---
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

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `params` | `AddPasswordParams` | Yes | Parameters for adding a password (password content, name, and validity settings, etc.) |

### 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) |

### Referenced Types

##### `interface` AddPasswordParams

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

##### `interface` SpecialUnlockMethodInfo

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


### Examples

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