mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Re-implement remove_cloud_password using SRP
This commit is contained in:
parent
40ecc082a6
commit
efc6023b08
@ -16,9 +16,8 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from hashlib import sha256
|
|
||||||
|
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions, types
|
||||||
|
from .utils import compute_check
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
@ -31,25 +30,26 @@ class RemoveCloudPassword(BaseClient):
|
|||||||
Your current password.
|
Your current password.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True on success, False otherwise.
|
True on success.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
||||||
|
``ValueError`` in case there is no cloud password to remove.
|
||||||
"""
|
"""
|
||||||
r = self.send(functions.account.GetPassword())
|
r = self.send(functions.account.GetPassword())
|
||||||
|
|
||||||
if isinstance(r, types.account.Password):
|
if not r.has_password:
|
||||||
password_hash = sha256(r.current_salt + password.encode() + r.current_salt).digest()
|
raise ValueError("There is no cloud password to remove")
|
||||||
|
|
||||||
return self.send(
|
self.send(
|
||||||
functions.account.UpdatePasswordSettings(
|
functions.account.UpdatePasswordSettings(
|
||||||
current_password_hash=password_hash,
|
password=compute_check(r, password),
|
||||||
new_settings=types.account.PasswordInputSettings(
|
new_settings=types.account.PasswordInputSettings(
|
||||||
new_salt=b"",
|
new_algo=types.PasswordKdfAlgoUnknown(),
|
||||||
new_password_hash=b"",
|
new_password_hash=b"",
|
||||||
hint=""
|
hint=""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
return False
|
return True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user