Make cloud password methods raise NotImplementedError. See #178

The protocol changed (SRP) and they are currently not re-implemented.
This commit is contained in:
Dan 2018-12-23 01:05:44 +01:00
parent 7ee89c94cb
commit 0371f4ce8b
3 changed files with 59 additions and 64 deletions

View File

@ -16,10 +16,6 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import os
from hashlib import sha256
from pyrogram.api import functions, types
from ...ext import BaseClient
@ -46,23 +42,25 @@ class ChangeCloudPassword(BaseClient):
Raises:
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
"""
r = self.send(functions.account.GetPassword())
raise NotImplementedError
if isinstance(r, types.account.Password):
current_password_hash = sha256(r.current_salt + current_password.encode() + r.current_salt).digest()
new_salt = r.new_salt + os.urandom(8)
new_password_hash = sha256(new_salt + new_password.encode() + new_salt).digest()
return self.send(
functions.account.UpdatePasswordSettings(
current_password_hash=current_password_hash,
new_settings=types.account.PasswordInputSettings(
new_salt=new_salt,
new_password_hash=new_password_hash,
hint=new_hint
)
)
)
else:
return False
# r = self.send(functions.account.GetPassword())
#
# if isinstance(r, types.account.Password):
# current_password_hash = sha256(r.current_salt + current_password.encode() + r.current_salt).digest()
#
# new_salt = r.new_salt + os.urandom(8)
# new_password_hash = sha256(new_salt + new_password.encode() + new_salt).digest()
#
# return self.send(
# functions.account.UpdatePasswordSettings(
# current_password_hash=current_password_hash,
# new_settings=types.account.PasswordInputSettings(
# new_salt=new_salt,
# new_password_hash=new_password_hash,
# hint=new_hint
# )
# )
# )
# else:
# return False

View File

@ -16,10 +16,6 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import os
from hashlib import sha256
from pyrogram.api import functions, types
from ...ext import BaseClient
@ -48,22 +44,24 @@ class EnableCloudPassword(BaseClient):
Raises:
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
"""
r = self.send(functions.account.GetPassword())
raise NotImplementedError
if isinstance(r, types.account.NoPassword):
salt = r.new_salt + os.urandom(8)
password_hash = sha256(salt + password.encode() + salt).digest()
return self.send(
functions.account.UpdatePasswordSettings(
current_password_hash=salt,
new_settings=types.account.PasswordInputSettings(
new_salt=salt,
new_password_hash=password_hash,
hint=hint,
email=email
)
)
)
else:
return False
# r = self.send(functions.account.GetPassword())
#
# if isinstance(r, types.account.NoPassword):
# salt = r.new_salt + os.urandom(8)
# password_hash = sha256(salt + password.encode() + salt).digest()
#
# return self.send(
# functions.account.UpdatePasswordSettings(
# current_password_hash=salt,
# new_settings=types.account.PasswordInputSettings(
# new_salt=salt,
# new_password_hash=password_hash,
# hint=hint,
# email=email
# )
# )
# )
# else:
# return False

View File

@ -16,9 +16,6 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from hashlib import sha256
from pyrogram.api import functions, types
from ...ext import BaseClient
@ -37,20 +34,22 @@ class RemoveCloudPassword(BaseClient):
Raises:
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
"""
r = self.send(functions.account.GetPassword())
raise NotImplementedError
if isinstance(r, types.account.Password):
password_hash = sha256(r.current_salt + password.encode() + r.current_salt).digest()
return self.send(
functions.account.UpdatePasswordSettings(
current_password_hash=password_hash,
new_settings=types.account.PasswordInputSettings(
new_salt=b"",
new_password_hash=b"",
hint=""
)
)
)
else:
return False
# r = self.send(functions.account.GetPassword())
#
# if isinstance(r, types.account.Password):
# password_hash = sha256(r.current_salt + password.encode() + r.current_salt).digest()
#
# return self.send(
# functions.account.UpdatePasswordSettings(
# current_password_hash=password_hash,
# new_settings=types.account.PasswordInputSettings(
# new_salt=b"",
# new_password_hash=b"",
# hint=""
# )
# )
# )
# else:
# return False