rubenlagus / TelegramApi

Java library to create Telegram Clients
MIT License
300 stars 108 forks source link

how to enable two step verfication #43

Open netGlobe opened 6 years ago

netGlobe commented 6 years ago

i need to enable two step verification,any code sample?

netGlobe commented 6 years ago

after checking this link https://github.com/rubenlagus/Tsupport/blob/master/TMessagesProj/src/main/java/org/telegram/ui/AccountPasswordActivity.java i found the solution

TLRequestAccountGetPassword tl=new TLRequestAccountGetPassword();
                        TLAbsAccountPassword result = kernelComm.getApi().doRpcCall(tl);
                        TLRequestAccountUpdatePasswordSettings ps=new 
                        TLRequestAccountUpdatePasswordSettings();
                        TLAccountPasswordInputSettings pss=new TLAccountPasswordInputSettings();
                        pss.setEmail("mail@mail.com");
                        pss.setFlags(3);
                        pss.setHint("hint");
                        byte[] new_salt=result.getNewSalt().getData();
                        byte[] salt = new byte[new_salt.length + 16];
                            new SecureRandom().nextBytes(salt);
                            System.arraycopy(new_salt, 0, salt, 0, new_salt.length);
                            new_salt = salt;
                        byte[] newPasswordBytes="password".getBytes();
                        byte[] hashs = new byte[new_salt.length * 2 + newPasswordBytes.length];
                        System.arraycopy(new_salt, 0, hashs, 0, new_salt.length);
                        System.arraycopy(newPasswordBytes, 0, hashs, newPasswordBytes.length, newPasswordBytes.length);
                        System.arraycopy(new_salt, 0, hashs, hashs.length - new_salt.length, new_salt.length);
                        TLBytes tb=new TLBytes(computeSHA256(hashs, 0, hashs.length));
                        pss.setNewPasswordHash(tb);
                        pss.setNewSalt(new TLBytes(new_salt));
                        ps.setNewSettings(pss);
                        ps.setCurrentPasswordHash(new TLBytes(new byte[0]));
                        TLBool res = kernelComm.getApi().doRpcCall(ps);

this works fine but seems password received by telegram is not that is inside the code sorry for dirty code