Comments (6)
@1pyxa1 What are you trying to do exactly? Remove the password? Change it? ...?
from pyrogram.
@delivrance Trying to set new password first time.
from pyrogram.
I found the solution. Tested it for setting new password first time and for changing it. Works great.
Here is my version:
def update_password_settings(client,
new_password,
current_password=None,
email=None,
hint='hint'):
r = client.send(functions.account.GetPassword())
salt_random = os.urandom(8)
salt = r.new_salt + salt_random
if current_password:
current_password = r.current_salt + current_password.encode() + \
r.current_salt
current_password_hash = sha256(current_password).digest()
else:
current_password_hash = salt
new_password = salt + new_password.encode('utf-8') + salt
new_password_hash = sha256(new_password).digest()
if email:
new_settings = types.account.PasswordInputSettings(
new_salt=salt,
new_password_hash=new_password_hash,
email=email,
hint=hint)
else:
new_settings = types.account.PasswordInputSettings(
new_salt=salt,
new_password_hash=new_password_hash,
hint=hint)
return client.send(functions.account.UpdatePasswordSettings(
current_password_hash, new_settings=new_settings))
Maybe it would be useful to add it to pyrogram/client/client.py for other users, what do you think?
from pyrogram.
Maybe it would be useful to add it to pyrogram/client/client.py for other users, what do you think?
Definitely! Being a pretty young project there's a lot to be added and suggestions are very welcome.
I was thinking about adding three different methods to create, change and remove the password, or maybe a single one that does everything? What do you think?
from pyrogram.
Personally I would prefer a single one that does everything. Maybe put there little more explanation. Because the code for three different methods will be pretty much the same. But of course it's up to you. And i think it's not so important which way to choose.
Here is my final tested version with removing a password also:
def update_password_settings(client,
new_password=None,
current_password=None,
email=None,
hint='hint'):
if new_password is None and current_password is None:
logging.warning("new_password is None and current_password is None.\
Nothing to do.")
return False
r = client.send(functions.account.GetPassword())
salt_random = os.urandom(8)
salt = r.new_salt + salt_random
if current_password:
current_password = r.current_salt + current_password.encode() + \
r.current_salt
current_password_hash = sha256(current_password).digest()
else:
current_password_hash = salt
if new_password:
new_password = salt + new_password.encode('utf-8') + salt
new_password_hash = sha256(new_password).digest()
else:
return client.send(functions.account.UpdatePasswordSettings(
current_password_hash,
new_settings=types.account.PasswordInputSettings(
new_salt=bytearray(),
new_password_hash=bytearray(),
hint=hint)))
if email:
new_settings = types.account.PasswordInputSettings(
new_salt=salt,
new_password_hash=new_password_hash,
email=email,
hint=hint)
else:
new_settings = types.account.PasswordInputSettings(
new_salt=salt,
new_password_hash=new_password_hash,
hint=hint)
return client.send(functions.account.UpdatePasswordSettings(
current_password_hash, new_settings=new_settings))
from pyrogram.
I've opted for three distinct methods, I think it's simpler to use this way: 8cc0fe1
from pyrogram.
Related Issues (20)
- Unable to connect due to network issues: Connection timed out HOT 1
- Hardcoded Session.START_TIMEOUT
- issue tiwh
- Trouble Accessing Messages Containing Quotes HOT 2
- Fetch more than 200 or filter by deleted / last seen a long time ago #4342 HOT 1
- Ability to specify session file path HOT 1
- Issue: Ban from 'pyrogramchat' Telegram Group Due to Verification Bot Malfunction HOT 1
- Slow Upload Speed HOT 1
- [400 PEER_ID_INVALID] but I met this peer in a group chat! On real client I can DM them. HOT 2
- 求大佬维护群聊管理员匿名用户的识别问题
- the handler receives the user's message twice
- Missing RDNS Parameter in proxy connection settings
- Missing Parameter in ban_member Method HOT 6
- Health Check HOT 1
- Document download problem
- [PROPOSAL] Pass the project to someone else HOT 3
- Message not received from a certain telegram channel HOT 17
- Can't send media due to 401(AuthKeyUnregistered) error HOT 1
- Clarification related to how it upload more than 50mb? HOT 3
- key error 0 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyrogram.