sirac emin topçu
sirac emin topçu

Reputation: 31

if statement works wrong in Python

I am trying to get "successful login" but it responds to me with "Please enter your new password: ". This is my code :

nvp=input("Please enter usernames and passwords: ")
nvp1= nvp.split(";")
nvp2=[]
names=[]
sd=[]
for x in nvp1 :
  nvp2.append(x)
  x= x.split(":")
  names.append(x[0])
  sd.append(x[1])
sd1=[]
for x in sd :
  sd1.append(x[:0:-1])
password=[]
c=0
while c != len(names) :
  n= names[c]
  n1=n[1:]
  p =sd1[c]
  p=p[len(n1):]
  password.append(p) 
  c += 1   
lm= input("Please enter last modification information: ")
lm= lm.split(";")
lmv=[]
for x in lm :
  c= 0
  c+=(int(x[x.index(":")+1])*10)
  c+=(int(x[x.index(" ")+1]))
  if (x[x.index(" ")+2]) == "0" : 
    c+=10 
  lmv.append(c)
un=input("Please enter the username: ")
if un in names:
  pw=input("Please enter the password: ")
  if pw in password :
    if lmv[names.index(un)] >= 6:
      p= input("Please enter your new password: ")
    else:
      print("Successful login")  
  else:
    print("Wrong password") 
else:
  print("Wrong username")  

my sample is :

Please enter usernames and passwords: coff33c4ke:cr0t4id@lgoff33c4ke;j0mesb0nd7:jredips?etaraK0mesb0nd7;hubblebubble:h.sneil@_etucubblebubble

Please enter last modification information: hubblebubble:0year(s) 10month(s);coff33c4ke:2year(s) 5month(s);j0mesb0nd7:0year(s) 5month(s)

Please enter the username: j0mesb0nd7

Please enter the password: Karate?spider

Successful login

Upvotes: 0

Views: 60

Answers (1)

Ryan Rau
Ryan Rau

Reputation: 148

I'm unable to comment so I'll make a post, but it's a bit hard to follow what you're trying to accomplish. I.E. what is lmv and what are you trying to accomplish with if lmv[names.index(un)] >= 6:?

If you step through your code and insert some print statements you'll see that given the input information provided

lmv = [11, 25, 5]
names.index(un) = 1
lmv[names.index(un)] = 25

Hence if lmv[names.index(un)] >= 6: is true and will prompt you to enter your new password.

Maybe you need to adjust that logic for calculating lmv

Upvotes: 1

Related Questions