|
| 1 | +# Login verificacion de datos |
| 2 | +# No se considero inyecion por SQL u otros metodos de ingreso. |
| 3 | +# @autor: Magno Efren |
| 4 | +# Youtube: https://www.youtube.com/c/MagnoEfren |
| 5 | + |
| 6 | +from tkinter import Tk, Button, Entry, Label, ttk, PhotoImage |
| 7 | +from tkinter import StringVar,END,HORIZONTAL,Frame,Toplevel |
| 8 | +import time |
| 9 | +import conexion |
| 10 | + |
| 11 | +class Login(Frame): |
| 12 | + def __init__(self, master, *args): |
| 13 | + super().__init__( master,*args) |
| 14 | + |
| 15 | + self.user_marcar = "Ingrese su correo" |
| 16 | + self.contra_marcar = "Ingrese su contraseña" |
| 17 | + self.fila1 = '' |
| 18 | + self.fila2 = '' |
| 19 | + self.datos = conexion.Registro_datos() |
| 20 | + self.widgets() |
| 21 | + |
| 22 | + def entry_out(self, event, event_text): |
| 23 | + if event['fg'] == 'black' and len(event.get()) ==0: |
| 24 | + event.delete(0, END) |
| 25 | + event['fg'] = 'grey' |
| 26 | + event.insert(0, event_text) |
| 27 | + |
| 28 | + if self.entry2.get() != 'Ingrese su contraseña': |
| 29 | + self.entry2['show'] ="" |
| 30 | + |
| 31 | + if self.entry2.get() != 'Ingrese su correo': |
| 32 | + self.entry2['show'] ="*" |
| 33 | + |
| 34 | + |
| 35 | + def entry_in(self, event): |
| 36 | + if event['fg'] == 'grey': |
| 37 | + event['fg'] = 'black' |
| 38 | + event.delete(0, END) |
| 39 | + |
| 40 | + if self.entry2.get() != 'Ingrese su contraseña': |
| 41 | + self.entry2['show'] = "*" |
| 42 | + |
| 43 | + if self.entry2.get() == 'Ingrese su contraseña': |
| 44 | + self.entry2['show'] = "" |
| 45 | + |
| 46 | + def salir(self): |
| 47 | + self.master.destroy() |
| 48 | + self.master.quit() |
| 49 | + |
| 50 | + def acceder_ventana_dos(self): |
| 51 | + for i in range(101): |
| 52 | + self.barra['value'] +=1 |
| 53 | + self.master.update() |
| 54 | + time.sleep(0.02) |
| 55 | + |
| 56 | + self.master.withdraw() |
| 57 | + self.ventana_dos = Toplevel() |
| 58 | + self.ventana_dos.title('Segunda Ventana') |
| 59 | + self.ventana_dos.geometry('500x500+400+80') |
| 60 | + self.ventana_dos.protocol("WM_DELETE_WINDOW", self.salir) |
| 61 | + self.ventana_dos.config(bg= 'white') |
| 62 | + self.ventana_dos.state('zoomed') |
| 63 | + |
| 64 | + Label(self.ventana_dos, text='VENTANA DOS', font='Arial 40', bg= 'white').pack(expand=True) |
| 65 | + Button(self.ventana_dos, text='Salir', font='Arial 10', bg= 'red', command= self.salir).pack(expand=True) |
| 66 | + |
| 67 | + |
| 68 | + def verificacion_users(self): |
| 69 | + self.indica1['text'] = '' |
| 70 | + self.indica2['text'] = '' |
| 71 | + users_entry = self.entry1.get() |
| 72 | + password_entry = self.entry2.get() |
| 73 | + |
| 74 | + if users_entry!= self.user_marcar or self.contra_marcar != password_entry: |
| 75 | + users_entry = str("'" + users_entry + "'") |
| 76 | + password_entry = str("'" + password_entry + "'") |
| 77 | + |
| 78 | + dato1 = self.datos.busca_users(users_entry) |
| 79 | + dato2 = self.datos.busca_password(password_entry) |
| 80 | + |
| 81 | + self.fila1 = dato1 |
| 82 | + self.fila2 = dato2 |
| 83 | + |
| 84 | + if self.fila1 == self.fila2: |
| 85 | + if dato1 == [] and dato2 ==[]: |
| 86 | + self.indica2['text'] = 'Contraseña incorrecta' |
| 87 | + self.indica1['text'] = 'Usuario incorrecto' |
| 88 | + else: |
| 89 | + |
| 90 | + if dato1 ==[]: |
| 91 | + self.indica1['text'] = 'Usuario incorrecto' |
| 92 | + else: |
| 93 | + dato1 = dato1[0][1] |
| 94 | + |
| 95 | + if dato2 ==[]: |
| 96 | + self.indica2['text'] = 'Contraseña incorrecta' |
| 97 | + else: |
| 98 | + dato2 = dato2[0][2] |
| 99 | + |
| 100 | + if dato1 != [] and dato2 != []: |
| 101 | + self.acceder_ventana_dos() |
| 102 | + else: |
| 103 | + self.indica1['text'] = 'Usuario incorrecto' |
| 104 | + self.indica2['text'] = 'Contraseña incorrecta' |
| 105 | + |
| 106 | + def widgets(self): |
| 107 | + self.logo = PhotoImage(file ='logo.png') |
| 108 | + Label(self.master, image= self.logo, bg='DarkOrchid1',height=150, width=150).pack() |
| 109 | + Label(self.master, text= 'Usuario', bg='DarkOrchid1', fg= 'black', font= ('Lucida Sans', 16, 'bold')).pack(pady=5) |
| 110 | + self.entry1 = Entry(self.master, font=('Comic Sans MS', 12),justify = 'center', fg='grey',highlightbackground = "#E65561", |
| 111 | + highlightcolor= "green2", highlightthickness=5) |
| 112 | + self.entry1.insert(0, self.user_marcar) |
| 113 | + self.entry1.bind("<FocusIn>", lambda args: self.entry_in(self.entry1)) |
| 114 | + self.entry1.bind("<FocusOut>", lambda args: self.entry_out(self.entry1, self.user_marcar)) |
| 115 | + self.entry1.pack(pady=4) |
| 116 | + |
| 117 | + self.indica1 = Label(self.master, bg='DarkOrchid1', fg= 'black', font= ('Arial', 8, 'bold')) |
| 118 | + self.indica1.pack(pady=2) |
| 119 | + |
| 120 | + # contraseña y entry |
| 121 | + Label(self.master, text= 'Contraseña', bg='DarkOrchid1', fg= 'black', font= ('Lucida Sans', 16, 'bold')).pack(pady=5) |
| 122 | + self.entry2 = Entry(self.master,font=('Comic Sans MS', 12),justify = 'center', fg='grey',highlightbackground = "#E65561", |
| 123 | + highlightcolor= "green2", highlightthickness=5) |
| 124 | + self.entry2.insert(0, self.contra_marcar) |
| 125 | + self.entry2.bind("<FocusIn>", lambda args: self.entry_in(self.entry2)) |
| 126 | + self.entry2.bind("<FocusOut>", lambda args: self.entry_out(self.entry2, self.contra_marcar)) |
| 127 | + self.entry2.pack(pady=4) |
| 128 | + |
| 129 | + self.indica2 = Label(self.master, bg='DarkOrchid1', fg= 'black', font= ('Arial', 8, 'bold')) |
| 130 | + self.indica2.pack(pady=2) |
| 131 | + |
| 132 | + Button(self.master, text= 'Iniciar Sesion', command = self.verificacion_users,activebackground='magenta', bg='#D64E40', font=('Arial', 12,'bold')).pack(pady=10) |
| 133 | + |
| 134 | + estilo = ttk.Style() |
| 135 | + estilo.theme_use('clam') |
| 136 | + estilo.configure("TProgressbar", foreground='red', background='black',troughcolor='DarkOrchid1', |
| 137 | + bordercolor='#970BD9',lightcolor='#970BD9', darkcolor='black') |
| 138 | + self.barra = ttk.Progressbar(self.master, orient= HORIZONTAL, length=200, mode='determinate', maximum=100, style="TProgressbar") |
| 139 | + self.barra.pack() |
| 140 | + Button(self.master, text= 'Salir', bg='DarkOrchid1',activebackground='DarkOrchid1', bd=0, fg = 'black', font=('Lucida Sans', 15,'italic'),command= self.salir).pack(pady=10) |
| 141 | + |
| 142 | +if __name__ == "__main__": |
| 143 | + ventana = Tk() |
| 144 | + ventana.config(bg='DarkOrchid1') |
| 145 | + ventana.geometry('350x500+500+50') |
| 146 | + ventana.overrideredirect(1) |
| 147 | + ventana.resizable(0,0) |
| 148 | + app = Login(ventana) |
| 149 | + app.mainloop() |
0 commit comments