Validation username and password with some condtion - python-3.x

So I have to create code that validates (ask username and password) whether a password:
Contains at least 1 number
Contains at least 1 capital letter
Contains at least 1 small letter
Contains at least 1 special symbol
and again ask the username and password (the previous one that we entered) if enter the wrong one after 3rd attempt it will print account blocked!

I am not sure about the contains statements. I know you can just assign a variable += 1 every time they enter an incorrect or invalid password until that variable hits a certain number (3). Then it would print out a statement that says something along the lines of "Blocked".

Related

Excel formula on cell for valid password

I'm creating a template for importing users in bulk to the system, one of the columns requires to input password,
I would like to create a condition on the [password] cell, in order to indicate to the person that input the details that the password is valid
those are the conditions:
Password must contain at least
6 characters
1 symbol
1 number
1 letter
This is what I tried : MEDIAN(6) AND (OR),EXACT(LOWER()))) but no luck.
all the symbols are valid but the values of the characters must be in English
is it possible?
A password-validator immediately screamed 'regular-expressions'. Will you want to go down the path of VBA, you'd require the following pattern:
^(?=.*?[!#$])(?=.*?[A-Za-z])(?=.*?\d).{6,}$
See an online demo
To mimic this in relative easy native functionality you could go with xpath-expressions:
=NOT(ISERROR(FILTERXML("<t><s>"&LOWER(A1)&"</s></t>","//s[translate(.,'abcdefghijklmnopqrstuvwxyz','')!=.][translate(.,'0123456789','')!=.][translate(.,'!#$','')!=.][string-length()>=6]")))
translate(.,'abcdefghijklmnopqrstuvwxyz','')!=.] would mimic the positive lookahead for any letter;
[translate(.,'0123456789','')!=.] would mimic the positive lookahead for any number;
[translate(.,'!#$','')!=.] would mimic the positive lookahead for any symbol (as given in the character class);
[string-length()>=6] would mimic the 6+ characters needed for valid input.
Well, I have done this in the few minutes between posting the comment and this answer, you can expand it to include whatever other conditions you want:
and(len(A1)>=6,MAX(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9},A1,1),"")))
is the formula used in the data validation. Youi can see that A1 meets the length >=6 but I have not controlled that the count of numbers, hiowever you can add that.

Python 3.8: require 2nd letter as uppercase value in password

I have to ask user to enter password which meets specific requirements like:
minimum 8 long;
contain at least on number;
to have at least one capital letter;
First three requirements I have solved but I'm unable to find solution for:
second letter has to be capital;
What should be in algorithm that checks if correct value is entered?
I guess string.upper() wont help me in this case because I need to ask user for correct input value not converting existing one.
Kind regards,
J.
You can use the .isupper() function to check if a character is uppercase.
string = "aBcdef"
if string[1].isupper():
# second letter is uppercase
For your case, I would be careful since you are also asking for a number in the password. You have to make sure the second character is not a number when you check it for uppercase because it will return false.

Charge Account Validation Python project

Design a program that asks the user to enter a charge account number.
The program should determine whether the number is valid by
comparing it to the following list of valid charge account numbers:
5658845 4520125 7895122 8777541 8451277
1302850
8080152 4562555 5552012 5050552 7825877
1250255
1005231 6545231 3852085 7576651 7881200
4581002
These numbers should be stored in an array. Use the sequential search
algorithm to locate the number entered by the user. If the number is in
the array, the program should display a message indicating the number
is valid. If the number is not in the array, the program should display a
message indicating the number is invalid.
Create a data file, valid_numbers.txt, containing the valid charge account numbers as listed in the book.
Create a data file, possible_valid numbers, containing a list of possible valid numbers (such as those entered by the user). You will create this file. Include at least 10 numbers, with approximately half valid and half invalid.
Compare each charge account number from the file, possible valid numbers, to see if it is listed as a valid number in the file valid_numbers.txt.
Create an output file, results.txt which lists the possible valid numbers and the result of validity checking. Create a list of numbers, followed by "VALID", or "INVALID". Space and align neatly.
Place your name and student ID at the top of the output file.
The output should look similar to:
What output should look like
****Below is my code****
ValidNumbers = open("possible_valid numbers.txt", "r")
Account_Number = int(input("Please enter your charge acount number "))
flag = 0
with open('valid_numbers.txt') as f:
lines = (f.read().splitlines())
numbers =[int(e.strip()) for e in lines]
for eachelement in numbers :
if eachelement==Account_Number :
print ('The number is valid')
flag =1
break;
if (flag ==0) :
print ('The number is invalid')
ValidNumbers.close()
I don't know how to complete part 4
Your code is a bit off from the homework assignment, I suggest that you use search engines to research code sniplets on how to complete the tasks of the assignment:
Step 1 -- this is a manual process, no code required
Step 2 -- this is a manual process, no code required
Step 3 -- you need to write code to:
read file created in Step 1
read file created in Step 2
then compare the two, keep the valid checks
Step 4 -- you need to:
create a new file
write a header (which is specified in Step 5)
write the results from Step 3
Step 5 -- actually done in Step 4
Step 6 -- this is a manual step, no code required
Good Luck !

Convert Formula Numerical Value to Matched Strings

I have the following formula that checks a username against a range of usernames, determines whether that username belongs to one of three domains, and whether that username is marked as an Administrator:
=SUMPRODUCT(COUNTIFS(Tbl_Data[Username],Rng_ITEmp,Tbl_Data[Domain],{"D1","D2","D3"},Tbl_Data[Member of Groups], "*Administrators*"))
This formula works wonderfully! I'd like to dig a little deeper though and actually print out the usernames that satisfied this query. Is there a way to go from this equation to the values that came back as TRUE?

COUNTIF Partial Match

I am working on a password audit, and one of the tasks I'm trying to solve is counting the number of instances a username is present in the password. For instance, the username might be 'mikeb' and their password is 'mikeb123'.
Searching for a username in a password is simple enough: COUNTIF(A:A, "mikeb")
The problem I'm running into is how to I check A1 against B1, A2 against B2, for the entire column, and add up the number of times that B contained A.
Currently I'm using a workaround where I make the comparison then count the number of true values in a separate column. I'd like to get away from another column if possible.
EDIT: Per request, dummy data:
Username Password Password Contains Username?
Bob BobHasASneakyPa$$word TRUE
Carol No1LikesUCarol TRUE
Admin <>##Admin##<> TRUE
Brian ;Ui6$m8/4??k3&)r7 FALSE
This is what my data looks like right now. I am using COUNTIF(A2, "*" & B2 & "*")>0 for the third column, then doing COUNTIF(C:C, "TRUE") to count up the # of times this happens. Ideally I'd combine these into one equation.
Try using
=SUMPRODUCT(--ISNUMBER(SEARCH(A2:A5,B2:B5)))
I've tested this on your dummy data and searched for the username in the password. It returns an answer of 3 which would be the same as summing your third column.
You could also make this case sensitive if needs be by changing SEARCH to FIND

Resources