This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from Tkinter import * | |
import tkMessageBox | |
global bandera, bandera1, bandera2, bandera3, bandera4 | |
bandera=0 | |
bandera1=0 | |
bandera2=0 | |
bandera3=0 | |
bandera4=0 | |
class app(): | |
def __init__(self): | |
self.ventana= Tk() | |
self.ventana.title('Nombre de Usario y contrasna') | |
self.ventana.geometry('500x500') | |
self.inicio() | |
self.ventana.mainloop() | |
def inicio(self): | |
self.etiqueta = Label(self.ventana,text='Dame Usuario:',font=("Arial", 12, "bold")) | |
self.etiqueta.grid(row=2, column=4, padx=(20,20), | |
pady=(20,20)) | |
self.usuario=StringVar() | |
self.ent_usuario=Entry(self.ventana,width=12,font=("Arial", 12), | |
textvariable=self.usuario) | |
self.ent_usuario.grid(row=2, column=5, padx=(20,20), | |
pady=(20,20)) | |
self.etiqueta2 = Label(self.ventana, text='Dame Password:',font=("Arial", 12, "bold")) | |
self.etiqueta2.grid(row=4, column=4, padx=(20, 20), | |
pady=(20, 20)) | |
self.password = StringVar() | |
self.ent_password = Entry(self.ventana, width=12,font=("Arial", 12), | |
textvariable=self.password) | |
self.ent_password.grid(row=4, column=5, padx=(20, 20), | |
pady=(20, 20)) | |
self.boton=Button(self.ventana, text='validar Usuario', | |
command= lambda: self.valida(self.ent_usuario.get())).place (x=310,y=15) | |
self.boton=Button(self.ventana, text='validar Contraseña', | |
command= lambda: self.valida1(self.ent_password.get())).place (x=310,y=85) | |
def valida(self,entrada1): | |
#self.ent_usuario=entrada1 | |
if len(entrada1) < 6: | |
tkMessageBox.showerror('Incorrecto Tamaño', | |
'Tiene que ser mayor de 6 caracteres') | |
self.ent_usuario.delete(0,'end') | |
#self.ventana.destroy() | |
#return app() | |
if len(entrada1) > 12: | |
tkMessageBox.showerror('Incorrecto Tamaño', | |
'No puede contener mas de 12 caracteres') | |
self.ent_usuario.delete(0, 'end') | |
#self.ventana.destroy() | |
#return app() | |
if (entrada1).isalnum() == FALSE: | |
tkMessageBox.showerror('Error', 'El usuario debe tener solo numeros o letras') | |
self.ent_usuario.delete(0, 'end') | |
#self.ventana.destroy() | |
#return app() | |
if len(entrada1) > 5 and len(entrada1) < 12 and (entrada1).isalnum() == TRUE: | |
tkMessageBox.showinfo('usuarios aceptado', 'El usuario es correcto') | |
def valida1(self, entrada2): | |
self.ent_password = entrada2 | |
for i in entrada2: # ciclo for que recorre caracter por caracter en la contraseña | |
if i.isspace() == True: # true tiene espacio | |
# print 'tiene espacio' | |
# print 'caraacter:',i | |
bandera = 0 | |
else: | |
bandera = 1 | |
# print bandera | |
if i.isupper() == True: #true tiene mayusculas | |
# print 'tiene mayuscualas' | |
# print 'caracter: ',i | |
bandera1 = 1 | |
# print bandera1 | |
if i.islower() == True: #true tiene minusculas | |
# print ' tiene minusculas' | |
# print 'caracter:', i | |
bandera2 = 1 | |
# print bandera2 | |
if i.isdigit() == True: #tiene numero | |
# print 'tiene numero' | |
# print 'caracter: ', i | |
bandera3 = 1 | |
# print bandera3 | |
if bandera == 0: | |
#print "el password no puede tener espacios" | |
tkMessageBox.showerror('Error', 'El password no puede tener espacios') | |
self.ent_password.delete(0, 'end') | |
#self.ventana.destroy() | |
#return app() | |
elif len(entrada2) < 8 and bandera == 1: | |
#print("el password no puede ser menor de 8 caracteres") | |
#bandera4 = 1 | |
tkMessageBox.showerror('Error', 'El password no puede ser menor de 8 caracteres') | |
self.ventana.destroy() | |
return app() | |
# La contraseña elegida no es segura: debe contener letras minúsculas, mayúsculas, números y al menos 1 carácter no alfanumérico | |
elif bandera == 1 and bandera1 == 1 and bandera2 == 1 and bandera3 == 1 : | |
#print("la contraseña es segura: tiene letras mayusculas, minusculas, numeros y al menos un caracter no alfanumerico") | |
tkMessageBox.showinfo('Passwor Correcto', 'El password es Seguro:tiene letras mayusculas, minusculas, numeros y al menos un caracter no alfanumerico ') | |
#self.ventana.destroy() | |
#return app() | |
self.etiqueta3 = Label(self.ventana,text='Fin de Validacion', | |
font=("agency fb",14)) | |
self.etiqueta3.grid(row=6, column=4, padx=(20,20), | |
pady=(20,20)) | |
self.etiqueta4 = Label(self.ventana,text='Esta es un version 3', | |
font=("agency fb", 14)) | |
self.etiqueta4.grid(row=7, column=4, padx=(20,20), | |
pady=(20,20)) | |
app = app() | |
No hay comentarios:
Publicar un comentario