Can you compare strings in C? Yes, you can compare strings in C using the strcmp()
function, along with other methods, to determine their lexicographical relationship, and this comprehensive guide on compare.edu.vn explores these techniques, offering clear examples and insights. Mastering string comparison is crucial for tasks like sorting, searching, and validating user input in C programming, and this article will help you understand how to perform these comparisons effectively and efficiently, enhancing your programming skills and ensuring robust code. Dive into the world of string comparison in C, including case-sensitive comparisons, partial string comparisons, and custom comparison functions to elevate your coding proficiency.
1. Understanding String Comparison in C
String comparison in C involves assessing the relationship between two or more strings to determine if they are identical, or if not, which one comes first lexicographically (alphabetical order). C doesn’t have a built-in string data type like some other languages; instead, strings are represented as arrays of characters terminated by a null character (”). Because of this representation, you can’t directly compare strings using operators like ==
. Instead, you must use functions designed for string comparison. These functions typically compare the strings character by character until a difference is found or the end of one or both strings is reached. String comparison is fundamental in many programming tasks, including sorting lists of words, searching for specific text within a larger body of text, and validating user input to ensure it matches expected formats or values.
1.1. Why Can’t We Use ==
to Compare Strings in C?
In C, strings are arrays of characters, and when you use the ==
operator, you are actually comparing the memory addresses of the string variables, not the content of the strings themselves. This means that even if two strings contain the same sequence of characters, if they are stored in different memory locations, the ==
operator will return false. This behavior is due to how C handles arrays and pointers. When you declare a string, you are essentially creating a pointer to the first character of the array. Therefore, comparing two strings with ==
only checks if the pointers point to the same memory location. This is why functions like strcmp()
are necessary; they compare the actual characters in the strings. To truly compare the content of two strings, you need to iterate through the characters of each string and compare them one by one, or use a function that does this for you.
1.2. Importance of String Comparison
String comparison is a fundamental operation in many applications. Consider the following scenarios:
- Sorting: When sorting a list of names or words, you need to compare strings to determine their correct order.
- Searching: Searching for a specific word or phrase in a document requires comparing the search term with the content of the document.
- Validation: Validating user input, such as usernames or passwords, involves comparing the input against a set of rules or a database of valid entries.
- Data Processing: Many data processing tasks involve comparing strings to categorize, filter, or transform data.
Without effective string comparison, these tasks would be difficult or impossible to implement. Therefore, understanding how to compare strings in C is crucial for developing robust and efficient applications.
2. The strcmp()
Function
The strcmp()
function is the primary tool for comparing strings in C. It is defined in the string.h
header file and provides a simple yet powerful way to determine the lexicographical relationship between two strings.
2.1. Syntax and Usage
The syntax for the strcmp()
function is as follows:
int strcmp(const char *str1, const char *str2);
str1
: A pointer to the first string to be compared.str2
: A pointer to the second string to be compared.
The function returns an integer value based on the comparison:
- 0: If the strings are identical.
- Negative value: If
str1
is lexicographically less thanstr2
. - Positive value: If
str1
is lexicographically greater thanstr2
.
Here’s a simple example of how to use strcmp()
:
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "apple";
char str2[] = "banana";
int result = strcmp(str1, str2);
if (result == 0) {
printf("The strings are identical.n");
} else if (result < 0) {
printf(""%s" comes before "%s".n", str1, str2);
} else {
printf(""%s" comes after "%s".n", str1, str2);
}
return 0;
}
In this example, strcmp()
compares “apple” and “banana”. Since “apple” comes before “banana” lexicographically, the function returns a negative value, and the program prints that “apple” comes before “banana”.
2.2. How strcmp()
Works
The strcmp()
function works by comparing the characters of the two strings one by one, starting from the first character. It continues comparing characters until it finds a difference or reaches the end of one or both strings (indicated by the null terminator ). The comparison is based on the ASCII values of the characters.
Here’s a step-by-step breakdown of how strcmp()
works:
- Initialization: The function starts by comparing the first characters of
str1
andstr2
. - Comparison: If the characters are the same, the function moves to the next character in both strings.
- Difference Found: If the characters are different, the function returns a value based on the difference between their ASCII values.
- If the ASCII value of the character in
str1
is less than the ASCII value of the character instr2
, the function returns a negative value. - If the ASCII value of the character in
str1
is greater than the ASCII value of the character instr2
, the function returns a positive value.
- If the ASCII value of the character in
- Null Terminator: If the function reaches the end of one or both strings (i.e., it encounters a null terminator), it checks the following:
- If both strings end at the same position, the function returns 0, indicating that the strings are identical.
- If
str1
ends beforestr2
, the function returns a negative value. - If
str2
ends beforestr1
, the function returns a positive value.
2.3. Practical Examples of strcmp()
To further illustrate how strcmp()
works, let’s look at some practical examples:
Example 1: Comparing Identical Strings
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "hello";
char str2[] = "hello";
int result = strcmp(str1, str2);
if (result == 0) {
printf("The strings are identical.n");
} else {
printf("The strings are different.n");
}
return 0;
}
Output:
The strings are identical.
In this case, strcmp()
returns 0 because both strings are exactly the same.
Example 2: Comparing Different Strings
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "apple";
char str2[] = "orange";
int result = strcmp(str1, str2);
if (result == 0) {
printf("The strings are identical.n");
} else if (result < 0) {
printf(""%s" comes before "%s".n", str1, str2);
} else {
printf(""%s" comes after "%s".n", str1, str2);
}
return 0;
}
Output:
"apple" comes before "orange".
Here, strcmp()
returns a negative value because “apple” comes before “orange” lexicographically.
Example 3: Case Sensitivity
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "Hello";
char str2[] = "hello";
int result = strcmp(str1, str2);
if (result == 0) {
printf("The strings are identical.n");
} else {
printf("The strings are different.n");
}
return 0;
}
Output:
The strings are different.
This example demonstrates that strcmp()
is case-sensitive. “Hello” and “hello” are considered different because the ASCII value of ‘H’ is different from the ASCII value of ‘h’.
Example 4: Comparing Strings with Numbers
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "file1";
char str2[] = "file10";
int result = strcmp(str1, str2);
if (result == 0) {
printf("The strings are identical.n");
} else if (result < 0) {
printf(""%s" comes before "%s".n", str1, str2);
} else {
printf(""%s" comes after "%s".n", str1, str2);
}
return 0;
}
Output:
"file1" comes before "file10".
In this case, strcmp()
compares the strings character by character. It compares ‘f’, ‘i’, ‘l’, ‘e’, and ‘1’ in both strings. Since all these characters are the same, it continues to the next character in each string. In “file1”, the next character is the null terminator , while in “file10”, the next character is ‘0’. Because the null terminator has an ASCII value of 0, which is less than the ASCII value of ‘0’ (which is 48),
strcmp()
returns a negative value.
These examples illustrate the basic usage and behavior of the strcmp()
function.
3. Alternative String Comparison Functions
While strcmp()
is the most commonly used function for comparing strings in C, there are other functions available that offer different functionalities or handle specific scenarios.
3.1. strncmp()
: Comparing a Limited Number of Characters
The strncmp()
function allows you to compare a specified number of characters from two strings. This can be useful when you only need to compare a portion of the strings or when you want to avoid comparing potentially long strings in their entirety.
3.1.1. Syntax and Usage
The syntax for the strncmp()
function is as follows:
int strncmp(const char *str1, const char *str2, size_t n);
str1
: A pointer to the first string to be compared.str2
: A pointer to the second string to be compared.n
: The maximum number of characters to compare.
The function returns an integer value based on the comparison:
- 0: If the first
n
characters of the strings are identical. - Negative value: If the first
n
characters ofstr1
are lexicographically less than the firstn
characters ofstr2
. - Positive value: If the first
n
characters ofstr1
are lexicographically greater than the firstn
characters ofstr2
.
3.1.2. Example of strncmp()
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "comparing";
char str2[] = "compare";
int n = 7; // Compare the first 7 characters
int result = strncmp(str1, str2, n);
if (result == 0) {
printf("The first %d characters are identical.n", n);
} else if (result < 0) {
printf("The first %d characters of "%s" come before "%s".n", n, str1, str2);
} else {
printf("The first %d characters of "%s" come after "%s".n", n, str1, str2);
}
return 0;
}
Output:
The first 7 characters are identical.
In this example, strncmp()
compares the first 7 characters of “comparing” and “compare”. Since the first 7 characters are the same (“compare”), the function returns 0.
3.1.3. Use Cases for strncmp()
strncmp()
is particularly useful in scenarios where you need to check if a string starts with a specific prefix or when you want to compare only a portion of a string.
- Checking for a Prefix: You can use
strncmp()
to determine if a string starts with a particular prefix. For example, you might want to check if a URL starts with “https://”. - File Type Detection: When processing files, you can use
strncmp()
to check the file header to determine the file type. - Command Parsing: In a command-line interface, you can use
strncmp()
to parse commands based on their initial characters.
3.2. strcasecmp()
: Case-Insensitive String Comparison (Non-Standard)
The strcasecmp()
function (or _stricmp()
on Windows) performs a case-insensitive comparison of two strings. This means that it treats uppercase and lowercase letters as the same. Note that strcasecmp()
is not a standard C function and may not be available on all systems. It is often provided by POSIX-compliant systems or as an extension by some compilers.
3.2.1. Syntax and Usage
The syntax for the strcasecmp()
function is as follows:
int strcasecmp(const char *str1, const char *str2);
str1
: A pointer to the first string to be compared.str2
: A pointer to the second string to be compared.
The function returns an integer value based on the comparison:
- 0: If the strings are identical, ignoring case.
- Negative value: If
str1
is lexicographically less thanstr2
, ignoring case. - Positive value: If
str1
is lexicographically greater thanstr2
, ignoring case.
3.2.2. Example of strcasecmp()
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "Hello";
char str2[] = "hello";
int result = strcasecmp(str1, str2);
if (result == 0) {
printf("The strings are identical (case-insensitive).n");
} else {
printf("The strings are different (case-insensitive).n");
}
return 0;
}
Output:
The strings are identical (case-insensitive).
In this example, strcasecmp()
returns 0 because it ignores the case difference between “Hello” and “hello”.
3.2.3. Implementing Case-Insensitive Comparison Manually
If strcasecmp()
is not available on your system, you can implement a case-insensitive comparison manually by converting both strings to lowercase (or uppercase) before comparing them using strcmp()
.
Here’s an example of how to do this:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int string_case_insensitive_compare(const char *str1, const char *str2) {
char str1_lower[100]; // Assuming a maximum length of 100
char str2_lower[100];
// Copy and convert str1 to lowercase
for (int i = 0; str1[i]; i++) {
str1_lower[i] = tolower(str1[i]);
str1_lower[i + 1] = '';
}
// Copy and convert str2 to lowercase
for (int i = 0; str2[i]; i++) {
str2_lower[i] = tolower(str2[i]);
str2_lower[i + 1] = '';
}
// Compare the lowercase strings
return strcmp(str1_lower, str2_lower);
}
int main() {
char str1[] = "Hello";
char str2[] = "hello";
int result = string_case_insensitive_compare(str1, str2);
if (result == 0) {
printf("The strings are identical (case-insensitive).n");
} else {
printf("The strings are different (case-insensitive).n");
}
return 0;
}
This code defines a function string_case_insensitive_compare()
that converts both input strings to lowercase and then uses strcmp()
to compare the lowercase versions.
3.2.4. Use Cases for Case-Insensitive Comparison
Case-insensitive comparison is useful in scenarios where you want to compare strings without regard to case.
- User Input Validation: When validating user input, such as usernames or email addresses, you may want to ignore case.
- Searching: When searching for text in a document, you may want to find matches regardless of case.
- Sorting: When sorting a list of strings, you may want to sort them alphabetically, ignoring case.
3.3. Custom Comparison Functions
In some cases, you may need to implement a custom string comparison function to meet specific requirements. For example, you might want to compare strings based on a different collating sequence or ignore certain characters during the comparison.
3.3.1. Example of a Custom Comparison Function
Here’s an example of a custom string comparison function that ignores spaces:
#include <stdio.h>
#include <string.h>
int string_ignore_spaces_compare(const char *str1, const char *str2) {
int i = 0, j = 0;
while (str1[i] != '' && str2[j] != '') {
// Skip spaces in str1
while (str1[i] == ' ') {
i++;
}
// Skip spaces in str2
while (str2[j] == ' ') {
j++;
}
// Compare characters
if (str1[i] != str2[j]) {
return (unsigned char)str1[i] - (unsigned char)str2[j];
}
// Move to the next character
i++;
j++;
}
// Skip trailing spaces
while (str1[i] == ' ') {
i++;
}
while (str2[j] == ' ') {
j++;
}
// Compare lengths after removing spaces
if (str1[i] == '' && str2[j] == '') {
return 0;
} else if (str1[i] == '') {
return -1;
} else {
return 1;
}
}
int main() {
char str1[] = "hello world";
char str2[] = " hello world ";
int result = string_ignore_spaces_compare(str1, str2);
if (result == 0) {
printf("The strings are identical (ignoring spaces).n");
} else {
printf("The strings are different (ignoring spaces).n");
}
return 0;
}
Output:
The strings are identical (ignoring spaces).
This code defines a function string_ignore_spaces_compare()
that compares two strings while ignoring spaces. The function skips spaces in both strings and compares the remaining characters.
3.3.2. Considerations for Custom Comparison Functions
When implementing custom comparison functions, keep the following in mind:
- Performance: Custom comparison functions can be slower than built-in functions like
strcmp()
, especially if they involve complex logic. Consider the performance implications when using custom functions in performance-critical applications. - Correctness: Ensure that your custom comparison function correctly implements the desired comparison logic and handles all possible cases.
- Maintainability: Document your custom comparison functions clearly to explain their behavior and usage.
4. Common Pitfalls and Best Practices
When working with string comparison in C, it’s important to be aware of common pitfalls and follow best practices to avoid errors and ensure the reliability of your code.
4.1. Null Termination
C strings are null-terminated, meaning that the end of the string is marked by a null character (). It’s crucial to ensure that your strings are properly null-terminated, especially when creating strings dynamically or manipulating them. Failure to null-terminate a string can lead to buffer overflows and other errors.
4.1.1. Example of a Missing Null Terminator
#include <stdio.h>
#include <string.h>
int main() {
char str[5];
str[0] = 'h';
str[1] = 'e';
str[2] = 'l';
str[3] = 'l';
// Missing null terminator
printf("String: %sn", str); // May print garbage or cause a crash
return 0;
}
In this example, the str
array is not null-terminated, which can lead to unpredictable behavior when you try to print it as a string.
4.1.2. Ensuring Null Termination
Always ensure that your strings are properly null-terminated. When creating strings dynamically, allocate enough memory to include the null terminator.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
char *str = (char *)malloc(6 * sizeof(char)); // Allocate space for 5 characters + null terminator
if (str == NULL) {
perror("Failed to allocate memory");
return 1;
}
str[0] = 'h';
str[1] = 'e';
str[2] = 'l';
str[3] = 'l';
str[4] = 'o';
str[5] = ''; // Add null terminator
printf("String: %sn", str);
free(str); // Free allocated memory
return 0;
}
4.2. Buffer Overflows
Buffer overflows occur when you write beyond the allocated memory of a string buffer. This can happen when copying strings, concatenating strings, or reading user input. Buffer overflows can lead to crashes, security vulnerabilities, and other serious problems.
4.2.1. Example of a Buffer Overflow
#include <stdio.h>
#include <string.h>
int main() {
char buffer[10];
char long_string[] = "This is a very long string";
strcpy(buffer, long_string); // Buffer overflow
printf("Buffer: %sn", buffer);
return 0;
}
In this example, strcpy()
copies long_string
into buffer
, which is only 10 bytes long. This causes a buffer overflow, as long_string
is much larger than buffer
.
4.2.2. Avoiding Buffer Overflows
To avoid buffer overflows, use functions like strncpy()
instead of strcpy()
. strncpy()
allows you to specify the maximum number of characters to copy, preventing you from writing beyond the allocated memory of the buffer.
#include <stdio.h>
#include <string.h>
int main() {
char buffer[10];
char long_string[] = "This is a very long string";
strncpy(buffer, long_string, sizeof(buffer) - 1); // Use strncpy to prevent overflow
buffer[sizeof(buffer) - 1] = ''; // Ensure null termination
printf("Buffer: %sn", buffer);
return 0;
}
In this example, strncpy()
copies at most 9 characters from long_string
into buffer
, leaving space for the null terminator.
4.3. Case Sensitivity
Remember that strcmp()
is case-sensitive. If you need to perform a case-insensitive comparison, use strcasecmp()
(if available) or implement a custom comparison function that converts the strings to lowercase or uppercase before comparing them.
4.4. Locale-Specific Comparisons
The strcmp()
function compares strings based on the ASCII values of the characters. This may not be appropriate for all languages or locales. If you need to perform locale-specific string comparisons, use the strcoll()
function, which takes into account the current locale settings.
4.5. Error Handling
When working with strings, it’s important to handle errors gracefully. For example, if you are reading strings from user input, check for errors such as invalid characters or excessive length. If you are allocating memory for strings dynamically, check for allocation failures.
4.6. Code Readability
Write your code in a clear and readable style. Use meaningful variable names, add comments to explain your code, and follow consistent indentation and formatting conventions. This will make your code easier to understand, maintain, and debug.
5. String Comparison in Real-World Applications
String comparison is used extensively in various real-world applications. Here are some examples:
5.1. Text Editors and Word Processors
Text editors and word processors use string comparison for features such as:
- Search and Replace: Finding and replacing specific text within a document.
- Spell Checking: Comparing words in a document against a dictionary of valid words.
- Sorting: Sorting lines of text alphabetically.
- Syntax Highlighting: Identifying keywords and other language elements based on string matching.
5.2. Database Management Systems
Database management systems use string comparison for:
- Querying: Searching for records that match specific criteria.
- Indexing: Creating indexes to speed up data retrieval.
- Sorting: Sorting query results.
- Data Validation: Ensuring that data conforms to specified formats and constraints.
5.3. Operating Systems
Operating systems use string comparison for:
- File System Operations: Comparing file names and paths.
- Command Parsing: Interpreting commands entered by the user.
- User Authentication: Verifying usernames and passwords.
- Process Management: Identifying and managing processes based on their names.
5.4. Web Servers
Web servers use string comparison for:
- URL Routing: Mapping URLs to specific handlers.
- Cookie Handling: Parsing and comparing cookie values.
- HTTP Header Processing: Interpreting HTTP headers.
- Input Validation: Validating user input in forms.
5.5. Programming Languages
Programming languages use string comparison for:
- Lexical Analysis: Tokenizing source code.
- Parsing: Building abstract syntax trees.
- Symbol Table Management: Storing and retrieving information about variables and functions.
- Code Generation: Generating machine code or bytecode.
6. Advanced String Comparison Techniques
Beyond the basic string comparison functions, there are more advanced techniques that can be used to perform complex string comparisons.
6.1. Regular Expressions
Regular expressions are a powerful tool for pattern matching and string manipulation. They allow you to define complex patterns that can be used to search for, validate, or transform strings. C does not have built-in support for regular expressions, but you can use libraries such as regex.h
(POSIX regular expressions) or PCRE (Perl Compatible Regular Expressions) to work with regular expressions in C.
6.1.1. Example of Using Regular Expressions
#include <stdio.h>
#include <stdlib.h>
#include <regex.h>
int main() {
const char *string = "The quick brown fox jumps over the lazy dog";
const char *pattern = "fox";
regex_t regex;
int result;
// Compile the regular expression
if (regcomp(®ex, pattern, 0) != 0) {
fprintf(stderr, "Could not compile regular expression.n");
exit(1);
}
// Execute the regular expression
result = regexec(®ex, string, 0, NULL, 0);
if (result == 0) {
printf("The string matches the regular expression.n");
} else if (result == REG_NOMATCH) {
printf("The string does not match the regular expression.n");
} else {
fprintf(stderr, "Regular expression execution failed.n");
exit(1);
}
// Free the regular expression
regfree(®ex);
return 0;
}
In this example, the regular expression “fox” is used to search for the word “fox” in the string “The quick brown fox jumps over the lazy dog”.
6.1.2. Use Cases for Regular Expressions
Regular expressions are useful in a wide range of applications, including:
- Data Validation: Validating email addresses, phone numbers, and other data formats.
- Text Extraction: Extracting specific information from text, such as URLs or dates.
- Search and Replace: Performing complex search and replace operations.
- Log Analysis: Analyzing log files to identify patterns and anomalies.
6.2. Fuzzy String Matching
Fuzzy string matching, also known as approximate string matching, is a technique for finding strings that are similar to a given pattern, even if they are not exactly the same. This can be useful when dealing with noisy or incomplete data.
6.2.1. Levenshtein Distance
One common algorithm for fuzzy string matching is the Levenshtein distance, which measures the number of edits (insertions, deletions, or substitutions) required to transform one string into another.
6.2.2. Example of Levenshtein Distance
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int levenshtein_distance(const char *str1, const char *str2) {
int len1 = strlen(str1);
int len2 = strlen(str2);
int matrix[len1 + 1][len2 + 1];
int i, j;
for (i = 0; i <= len1; i++) {
matrix[i][0] = i;
}
for (j = 0; j <= len2; j++) {
matrix[0][j] = j;
}
for (i = 1; i <= len1; i++) {
for (j = 1; j <= len2; j++) {
int cost = (str1[i - 1] == str2[j - 1]) ? 0 : 1;
matrix[i][j] = (matrix[i - 1][j] + 1 < matrix[i][j - 1] + 1) ? matrix[i - 1][j] + 1 : matrix[i][j - 1] + 1;
if (matrix[i][j] > matrix[i - 1][j - 1] + cost) {
matrix[i][j] = matrix[i - 1][j - 1] + cost;
}
}
}
return matrix[len1][len2];
}
int main() {
const char *str1 = "kitten";
const char *str2 = "sitting";
int distance = levenshtein_distance(str1, str2);
printf("Levenshtein distance between "%s" and "%s" is %dn", str1, str2, distance);
return 0;
}
Output:
Levenshtein distance between "kitten" and "sitting" is 3
This code calculates the Levenshtein distance between “kitten” and “sitting”, which is 3.
6.2.3. Use Cases for Fuzzy String Matching
Fuzzy string matching is useful in applications such as:
- Spell Checking: Suggesting corrections for misspelled words.
- Search: Finding search results that are similar to the search query.
- Data Integration: Matching records from different data sources that may contain errors or inconsistencies.
6.3. Hashing
Hashing is a technique for mapping strings to fixed-size values (hash codes). Hash codes can be used to quickly compare strings for equality. If two strings have different hash codes, they are definitely different. However, if two strings have the same hash code, they may or may not be the same (this is known as a hash collision).
6.3.1. Example of Using Hashing for String Comparison
#include <stdio.h>
#include <string.h>
#include <stdint.h>
// Simple hash function (not suitable for security-sensitive applications)
uint32_t string_hash(const char *str) {
uint32_t hash = 5381;
int c;
while ((c = *str++)) {
hash = ((hash << 5) + hash) + c; // hash * 33 + c
}
return hash;
}
int main() {
const char *str1 = "hello";
const char *str2 = "hello";
const char *str3 = "world";
uint32_t hash1 = string_hash(str1);
uint32_t hash2 = string_hash(str2);
uint32_t hash3 = string_hash(str3);
printf("Hash of "%s" is %un", str1, hash1);
printf("Hash of "%s" is %un", str2, hash2);
printf("Hash of "%s" is %un", str3, hash3);
if (hash1 == hash2) {
printf("The strings "%s" and "%s" are likely the same.n", str1, str2);
} else {
printf("The strings "%s" and "%s" are definitely different.n", str1, str2);
}
if (hash1 == hash3) {
printf("The strings "%s" and "%s" are likely the same.n", str1, str3);
} else {
printf("The strings "%s" and "%s" are definitely different.n", str1, str3);
}
return 0;
}
In this example, the string_hash()
function calculates a hash code for each string. The hash codes are then compared to determine if the strings are likely the same or definitely different.
6.3.2. Use Cases for Hashing
Hashing is useful in applications such as:
- Hash Tables: Implementing hash tables for efficient data storage and retrieval.
- Data Integrity: Verifying the integrity of data by comparing hash codes.
- Password Storage: St