GramJS

account.UpdatePasswordSettings

Set a new 2FA password

Example

const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result = await client.invoke(
    new Api.account.UpdatePasswordSettings({
      password: new Api.InputCheckPasswordSRP({
        srpId: BigInt("-4156887774564"),
        a: Buffer.from("arbitrary data here"),
        m1: Buffer.from("arbitrary data here"),
      }),
      newSettings: new Api.account.PasswordInputSettings({
        newAlgo: new Api.PasswordKdfAlgoUnknown({}),
        newPasswordHash: Buffer.from("arbitrary data here"),
        hint: "some string here",
        email: "some string here",
        newSecureSettings: new Api.SecureSecretSettings({
          secureAlgo: new Api.SecurePasswordKdfAlgoUnknown({}),
          secureSecret: Buffer.from("arbitrary data here"),
          secureSecretId: BigInt("-4156887774564"),
        }),
      }),
    })
  );
  console.log(result); // prints the result
})();
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result: Api.Bool = await client.invoke(
    new Api.account.UpdatePasswordSettings({
      password: new Api.InputCheckPasswordSRP({
        srpId: BigInt("-4156887774564"),
        a: Buffer.from("arbitrary data here"),
        m1: Buffer.from("arbitrary data here"),
      }),
      newSettings: new Api.account.PasswordInputSettings({
        newAlgo: new Api.PasswordKdfAlgoUnknown({}),
        newPasswordHash: Buffer.from("arbitrary data here"),
        hint: "some string here",
        email: "some string here",
        newSecureSettings: new Api.SecureSecretSettings({
          secureAlgo: new Api.SecurePasswordKdfAlgoUnknown({}),
          secureSecret: Buffer.from("arbitrary data here"),
          secureSecretId: BigInt("-4156887774564"),
        }),
      }),
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
passwordInputCheckPasswordSRPThe old password (see SRP)
newSettingsaccount.PasswordInputSettingsThe new password (see SRP)

Result

Bool

Possible errors

CodeTypeDescription
400EMAIL_UNCONFIRMED_%dThe provided email isn't confirmed, %d is the length of the verification code that was just sent to the email: use account.verifyEmail to enter the received verification code and enable the recovery email.
400EMAIL_INVALIDThe specified email is invalid.
400EMAIL_UNCONFIRMEDEmail unconfirmed.
400NEW_SALT_INVALIDThe new salt is invalid.
400NEW_SETTINGS_INVALIDThe new password settings are invalid.
400PASSWORD_HASH_INVALIDThe provided password hash is invalid.
400SRP_ID_INVALIDInvalid SRP ID provided.
400SRP_PASSWORD_CHANGEDPassword has changed.

Can bots use this method?

No

Two-factor authentication

How to login to a user's account if they have enabled 2FA, how to change password.

account.verifyEmail

Verify an email address for telegram passport.