Skip to content

Commit efc6023

Browse files
committed
Re-implement remove_cloud_password using SRP
1 parent 40ecc08 commit efc6023

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

pyrogram/client/methods/password/remove_cloud_password.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from hashlib import sha256
20-
2119
from pyrogram.api import functions, types
20+
from .utils import compute_check
2221
from ...ext import BaseClient
2322

2423

@@ -31,25 +30,26 @@ def remove_cloud_password(self, password: str):
3130
Your current password.
3231
3332
Returns:
34-
True on success, False otherwise.
33+
True on success.
3534
3635
Raises:
3736
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
37+
``ValueError`` in case there is no cloud password to remove.
3838
"""
3939
r = self.send(functions.account.GetPassword())
4040

41-
if isinstance(r, types.account.Password):
42-
password_hash = sha256(r.current_salt + password.encode() + r.current_salt).digest()
43-
44-
return self.send(
45-
functions.account.UpdatePasswordSettings(
46-
current_password_hash=password_hash,
47-
new_settings=types.account.PasswordInputSettings(
48-
new_salt=b"",
49-
new_password_hash=b"",
50-
hint=""
51-
)
41+
if not r.has_password:
42+
raise ValueError("There is no cloud password to remove")
43+
44+
self.send(
45+
functions.account.UpdatePasswordSettings(
46+
password=compute_check(r, password),
47+
new_settings=types.account.PasswordInputSettings(
48+
new_algo=types.PasswordKdfAlgoUnknown(),
49+
new_password_hash=b"",
50+
hint=""
5251
)
5352
)
54-
else:
55-
return False
53+
)
54+
55+
return True

0 commit comments

Comments
 (0)