Facebook Password Changer GUI


The package required to run this app are given below:-

mechanize a python networking library based upon urllib, urllib2 it will automatically handle the https request and cookie for us, so no need to worry about them.

Tkinter a python gui  based library which is basically a wrapper function for Tcl/Tk programming language and very powerful for creating the GUI.

thread a threading module for python used to create the thread for the app.

And of course a python interpreter also required. :D

So here is my complete code for you people feel free to use them and again it is only for the educational purpose. I am not responsible for anything happens to you if you use it for the wrong way.

First we need to import our libraries


from Tkinter import *
import mechanize
import sys,thread


 After this we are going to create our gui class:-
The function __init__ below will initialize our class as a frame


 class fb(Frame):
    def __init__(self,master):
        Frame.__init__(self,master)
        self.email =StringVar()
        self.pwd = StringVar()
        self.link_dict=[]
        self.master.title('Facebook')
        self.create_widget()  #this will call our widget function


Now lets create our widget. This function will show a widget having the entry field for email and password for the app:-


def create_widget(self):
        self.frame = Frame(self.master,relief= GROOVE)
        Label(self.frame,text='Facebook Password Switcher!').pack()
        self.login_frame=Frame(self.frame,relief=GROOVE,borderwidth=2)
        self.lbl = Label(self.login_frame,text='Enter Your Login Details...')
        self.lbl.grid(row=0,columnspan=3,padx=10,pady=10)
        self.lbl2 =Label(self.login_frame,text='Email')
        self.lbl2.grid(row=1,column=0,sticky=W,padx=5)           
        self.lbl3=Label(self.login_frame,text='Password')
        self.lbl3.grid(row=2,column=0,sticky=W,padx=5,pady=5)
        self.entry=Entry(self.login_frame,textvariable=self.email)
        self.entry.grid(row=1,column=1,sticky=W,padx=5)
        self.entry2=Entry(self.login_frame,textvariable=self.pwd,show='*')
        self.entry2.grid(row=2,column=1,sticky=W,padx=5,pady=5)
        self.btn =Button(self.login_frame,text='Login',command=self.thr)
        self.btn.grid(row=3,columnspan=3,pady=5)
        self.txt = Text(self.login_frame,bg='black',fg='#00FF33')
        self.login_frame.pack()
        self.frame.pack()


The next function will create the thread for the textbox in which our text will be shown. Please note that I am not going to implement any thread synchronization because till now we just don't need to implement that. If you run the app without thread than it will simply hang up till the url will not be and whole process will go background we just can't see any output. To overcome this issue we implement a thread for the app.


#this will create the thread for the app   
    def thr(self):
        thread.start_new_thread(self.signin,())


Next function is our sign in function which will sign in to the website and changed the password. To understand this function please see my first tutorial.
If you don't want to show any input to your friend then you can simply change the printing values.


 def signin(self):
        self.txt.delete(0.0,END)
        self.txt.insert(0.0,'Opening the Website...\n')
        self.txt.grid(row=4,columnspan=3,padx=5,pady=5)
        self.br = mechanize.Browser()
        #setting the Headers
        self.br.addheaders = [('User-agent','Mozilla/11.0')]
        #Setting the robots
        self.br.set_handle_robots(False)
        self.ln = self.br.open('http://www.facebook.com')
        if self.ln:
            #self.txt.delete(0.0,END)
            self.txt.insert(END,'Website Opened Successfully!\n')
            self.user = self.email.get()
            self.paswrd = self.pwd.get()
          
            self.br.select_form(nr = 0)
            self.br.form['email'] = self.user  
            self.br.form['pass'] = self.paswrd   
            self.txt.insert(END,"Logging into the Website...\n")
            self.br.submit()
            #Reading the Ressponse
            for link in self.br.links():
              
                self.link_dict.append(link.url)
                      
            #Cheching whether we log in or not
          
            for i in range(len(self.link_dict)):
              
               if self.link_dict[i]=='/settings?tab=notifications&section=on_facebook' :
                  
                    open('fb_gui.html','w').write(self.br.response().read())
                    self.txt.insert(END,"Successfully Log into the Website\n")
                    #Creating a new link to click
                    #please indent this accordingly
                    self.new_link = self.br.click_link(url = "/settings?tab=notifications&section=on_facebook")
                    self.txt.insert(END,"Switching to Setting...\n")
                    #Openning the new link
                    self.br.open(self.new_link)
                    self.txt.insert(END,"Switch Successfully!\n")
                     #please indent this accordingly
                    self.new_link = self.br.click_link(url = 'https://www.facebook.com/settings?tab=account')
                    self.br.open(self.new_link)
                     #please indent this accordingly
                    self.new_link = self.br.click_link(url = '/settings?tab=account&section=password')
                    self.txt.insert(END,"Changing the Password...\n")
                    self.br.open(self.new_link)
                    #Selecting the password change form
                    self.br.select_form(nr = 0)

                    self.br.form['password_old'] = self.paswrd   
                    self.br.form['password_new'] = 'pasword you want'
                    self.br.form['password_confirm'] ='retype the pass you want'
                    self.br.submit()
                    self.res = self.br.response().read()
                    if self.res.find('Your password was incorrect.') >= 1:
                        self.txt.insert(END,"Password can't change Successfully!\n")
                        sys.exit(4)
                    else:
                        self.txt.insert(END,"Changed Successfully!\n")
                        sys.exit(0)
                elif (i+1) == len(self.link_dict):
                    self.txt.insert(END,"Login unsuccessfull!\n")
                    self.txt.insert(END,"Please check your username or password!\n")
                    sys.exit(4)
              
        else:
                self.txt.insert(END,'Link cannot open')


This is our main function which will kick of the app widget and run the app:-


def main():
    root = Tk()
    fb(root).mainloop()

#in these lines we are checking whether we are running it as a app or import it
if __name__ == '__main__':
    main()

And here is our outputs:-







If you don't know tkinter basics then let me know sothat I can post a tutorial on that too.
Please leave your comments behind.
Hope you guys enjoy this. Have a great day ahead and Happy Hacking...:)

No comments:

Post a Comment