MadelineProtoDocs/docs/docs/LOGIN.md

65 lines
2.6 KiB
Markdown
Raw Normal View History

2018-04-11 14:17:45 +02:00
---
title: Logging in
description: There are many ways you can login with MadelineProto.
image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png
---
2018-04-01 13:19:25 +02:00
# Logging in
There are many ways you can login with MadelineProto.
* [Automatic](#automatic)
* [Manual (user)](#manual-user)
* [Manual (bot)](#manual-bot)
* [Logout](#logout)
2019-06-01 18:08:28 +02:00
## Automatic ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
2018-04-01 13:19:25 +02:00
```php
2019-06-01 18:08:28 +02:00
yield $MadelineProto->start();
2018-04-01 13:19:25 +02:00
```
This will start an interactive login prompt via console (if running via CLI), or a login web UI (if running in the browser).
You will get to choose if login as user, or as bot.
## Manual (user)
```php
2019-06-01 18:08:28 +02:00
yield $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = yield $MadelineProto->complete_phone_login(readline('Enter the phone code: '));
2018-04-01 13:19:25 +02:00
if ($authorization['_'] === 'account.password') {
2019-06-01 18:08:28 +02:00
$authorization = yield $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
2018-04-01 13:19:25 +02:00
}
if ($authorization['_'] === 'account.needSignup') {
2019-06-01 18:08:28 +02:00
$authorization = yield $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
2018-04-01 13:19:25 +02:00
}
```
First, you must call `phone_login` to send the verification code, see [here for the parameters and the result](https://docs.madelineproto.xyz/phone_login.html).
Then, use `complete_phone_login` to complete the login, see [here for the parameters and the result](https://docs.madelineproto.xyz/complete_phone_login.html).
Use `complete_2FA_login` to complete the login to an account with 2FA enabled, see [here for the parameters and the result](https://docs.madelineproto.xyz/complete_2FA_login.html).
If the account does not have an account, use `complete_signup` to signup, see [here for the parameters and the result](https://docs.madelineproto.xyz/complete_signup.html).
## Manual (bot)
```php
2019-06-01 18:08:28 +02:00
yield $MadelineProto->bot_login('34298141894:aflknsaflknLKNFS');
2018-04-01 13:19:25 +02:00
```
Use `bot_login` to login as a bot, see [here for the parameters and the result](https://docs.madelineproto.xyz/bot_login.html).
Note that when you login as a bot, MadelineProto also logins using the [PWRTelegram](https://pwrtelegram.xyz) API, to allow persistant storage of peers, even after a logout and another login.
## Logout
```php
2019-06-01 18:08:28 +02:00
yield $MadelineProto->logout();
2018-04-01 13:19:25 +02:00
```
**If** you want to logout, you can use the logout function, see [here for the parameters and the result](https://docs.madelineproto.xyz/logout.html).
2018-04-01 13:55:07 +02:00
<a href="https://docs.madelineproto.xyz/docs/FEATURES.html">Next section</a>