Verification & Validation
Input Verification
Input/entry verification involves the process of confirming that the data has been entered as it was intended by the user or through automated input such as a barcode scanner.
Typical techniques include:
- Duplicate entry (e.g. for password setting)
- Checksums & Hashing (for barcode entry/scanning)
Duplicate Entry
When a website asks you to enter your password twice during the signup process, it is often referred to as "Password Confirmation" or "Password Verification." This practice aims to reduce the risk of users making typos or mistakes when entering their password for the first time.
Checksum Verification
The purpose of a checksum is to help detect errors, ensure data integrity, and provide a mechanism for verifying the accuracy of transmitted or stored data. I
t involves generating a fixed-size value (often a single number or a short string of characters) from a larger set of data, such as a file or a sequence of bytes.
They are used in data transmission, storage, library book ISBN number verification, credit cards.
What is the purpose of a checksum?
Luhn Algorithm
The credit card checksum, often implemented using the Luhn algorithm (also known as the "modulus 10" or "mod 10" algorithm), is a simple error-detection mechanism used to validate credit card numbers.
It detects the most common user errors when typing a credit card number, such as swapping numbers or duplicating a number by accident.
Luhn's algorithm validates identification numbers by reversing them, alternately doubling digits, subtracting 9 from numbers over 9, summing all digits, and checking if the total modulo 10 is zero.
Input Validation
Input validation is a process used in computer programming to ensure that the data entered by a user meets certain criteria or requirements.
Types of Input Validation
- Range Checking: Ensuring that the entered value falls within a specified range.
- Format Checking: Verifying that the input matches a specific format (e.g., email address, phone number).
- Length Checking: Limiting the length of input to ensure it does not exceed a certain number of characters.
- Presence Checking: Ensuring that a required field is not left blank.
- Whitelist/Blacklist Checking: Allowing or disallowing specific characters or patterns in the input.
Which of the following is a benefit of using input verification checksums?
Benefits of Input Validation
- Data Integrity: Validating user input helps maintain data integrity by preventing incorrect or inconsistent data from being stored.
- Improved Security: Input validation helps protect against malicious attacks such as SQL injection or cross-site scripting.
- Better User Experience: By prompting users to correct their input, input validation improves the overall user experience and usability of a program.
- Reduced Errors: Validating input reduces the chances of errors and ensures that the program operates as intended.
Presence Check
A presence check tests to see that the input is not blank, for instance on required fields within forms
# Presence check for user input
def user_input_presence_check():
user_input = input("Enter something: ")
if user_input:
print("You entered:", user_input)
else:
print("You didn't enter anything.")
# Test the user input presence check
user_input_presence_check()
Length Check
def check_length(input_string):
length = len(input_string)
return length
user_input = input("Enter a string: ")
length = check_length(user_input)
print("Length of the input string is:", length)
Explanation
In the above code, we define a function called check_length() which takes an input string as a parameter. Inside the function, we use the len() function to calculate the length of the input string. The length is then returned as the output.
Next, we ask the user to enter a string using the input() function and store it in the variable user_input. We then call the check_length() function, passing the user_input variable as an argument. The returned length is stored in the variable length.
Finally, we print out the length of the input string using the print() function.
Range Check
while True:
try:
age = int(input("Please enter your age: "))
if age < 0:
print("Age cannot be negative. Please try again.")
else:
print(f"Your age is: {age}")
break
except ValueError:
print("Invalid input. Please enter a valid integer for your age.")
Format Check
import re
while True:
email = input("Please enter your email address: ")
if re.match(r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$", email):
print(f"Valid email address: {email}")
break
else:
print("Invalid email address. Please enter a valid email.")
Introduction to Verification & Validation
- Input Verification
- Duplicate Entry
- Checksum Verification
- Luhn Algorithm
- Input Validation
- Benefits of Input Validation
- Presence Check
- Length Check
- Range Check
- Format Check