[comment]: # translation:outdated

[comment]: # ({19701d17-19701d17})
# user.login

[comment]: # ({/19701d17-19701d17})

[comment]: # ({c647dda4-c647dda4})
### 説明

`string/object user.login(object parameters)`

このメソッドを使用すると、APIにログインして認証トークンを生成できます

::: notewarning
このメソッドを使用する場合は[user.logout](/manual/api/reference/user/logout)を実行して、開いているセッションレコードが大量に生成されないようにする必要もあります。
:::

::: noteimportant
このメソッドは、認証されていないユーザーのみが使用でき、JSON-RPCリクエストで`auth`パラメーターを指定せずに呼び出す必要があります。
:::

[comment]: # ({/c647dda4-c647dda4})

[comment]: # ({f5a2373f-68f0a066})
### パラメータ

`(object)` ユーザー名とパスワードを含むパラメーター

このメソッドは、次のパラメーターを受け入れます。

|パラメータ|[タイプ](/manual/api/reference_commentary#data_types)|説明|
|--|--|------|
|**password**<br>(必須)|string|ユーザーパスワード|
|**username**<br>(必須)|string|ユーザー名|
|userData|flag|認証されたユーザーに関する情報|

[comment]: # ({/f5a2373f-68f0a066})

[comment]: # ({0c2cbc1a-bc924c62})
### 戻り値

`(string/object)` `userData`パラメータが使用されている場合、認証されたユーザーに関する情報を含むオブジェクトを返します。

[標準ユーザープロパティ](object#user)に加えて、次の情報が返されます。

|プロパティ|[タイプ](/manual/api/reference_commentary#data_types)|説明|
|--|--|------|
|debug\_mode|boolean|ユーザーに対してデバッグモードが有効になっているかどうか|
|gui\_access|integer|フロントエンドに対するユーザーの認証方法<br><br>値のリストは[ユーザーグループオブジェクト](/manual/api/reference/usergroup/object#user_group)の`gui_access`プロパティを参照してください|
|sessionid|string|認証トークン。次のAPIリクエストで使用する必要があります。|
|userip|string|ユーザーのIPアドレス|

::: notetip
試行が1回以上失敗した後でユーザーが正常に認証された場合、メソッドは`attempt_clock`,`attempt_failed`および`attempt_ip`プロパティの現在の値を返し、それらをリセットします。
:::

`userData`パラメータが使用されていない場合、メソッドは認証トークンを返します。

::: notetip
生成された認証トークンは記憶され、次のJSON-RPCリクエストの`auth`パラメータで使用される必要があります。 HTTP認証を使用する場合にも必要です。
:::

[comment]: # ({/0c2cbc1a-bc924c62})

[comment]: # ({b41637d2-b41637d2})
### 例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({b6af279d-46abbe5a})
#### ユーザー認証

ユーザー認証

Request:

```json
{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "username": "Admin",
        "password": "zabbix"
    },
    "id": 1
}
```

Response:

```json
{
    "jsonrpc": "2.0",
    "result": "0424bd59b807674191e7d77572075f33",
    "id": 1
}
```

[comment]: # ({/b6af279d-46abbe5a})

[comment]: # ({003ca569-8448c8ab})
#### 認証してユーザーの情報を要求する

認証してユーザーに関する追加情報を含めて返します。

Request:

```json
{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "username": "Admin",
        "password": "zabbix",
        "userData": true
    },
    "id": 1
}
```

Response:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "userid": "1",
        "username": "Admin",
        "name": "Zabbix",
        "surname": "Administrator",
        "url": "",
        "autologin": "1",
        "autologout": "0",
        "lang": "ru_RU",
        "refresh": "0",
        "theme": "default",
        "attempt_failed": "0",
        "attempt_ip": "127.0.0.1",
        "attempt_clock": "1355919038",
        "rows_per_page": "50",
        "timezone": "Europe/Riga",
        "roleid": "3",
        "type": 3,
        "debug_mode": 0,
        "userip": "127.0.0.1",
        "gui_access": "0",
        "sessionid": "5b56eee8be445e98f0bd42b435736e42"
    },
    "id": 1
}
```

[comment]: # ({/003ca569-8448c8ab})

[comment]: # ({22a14fca-22a14fca})
### 参照

-   [user.logout](logout)

[comment]: # ({/22a14fca-22a14fca})

[comment]: # ({7fd9f53c-7fd9f53c})
### ソース

CUser::login() in *ui/include/classes/api/services/CUser.php*.

[comment]: # ({/7fd9f53c-7fd9f53c})
