In: Computer Science
Write a script in C that will do the following :
1. Create the directory ZHW3.
2. Verify that the directory is created by display all information related to the directory and not just the name of the directory.
3. Assume that the input from the command is used to validate password strength. Here are a few assumptions for the password string.
• Length – minimum of 8 characters.
• Contain alphabets , numbers , and @ # $ % & * symbols.
• Include both the small and capital case letters.
If the password doesn’t comply with any of the above conditions, then the script should report it as a <Weak Password>. Otherwise, the script should report it as a <Strong Password>.
The script must save the strong password it in a password file ( password.txt ) in ZHW3 Directory. If the file does not exist , create the file.
Repeat until N or n is entered.
If you enter Y|y, then new password is entered from the keyboard
// C++ code to validate a password
#include<bits/stdc++.h>
using namespace std;
// A utility function to check
// whether a password is valid or not
char* dirname = "ZHW3";
bool isValid(string password)
{
// For checking if password length
// is between 8 and 15
if (!((password.length() >= 8) &&
(password.length() <= 15)))
return false;
// To check space
if (password.find(" ") !=
std::string::npos)
return false;
if (true)
{
int count = 0;
// Check digits from 0 to 9
for(int i = 0; i <= 9; i++)
{
// To convert int to string
string str1 = to_string(i);
if (password.find(str1) !=
std::string::npos)
count = 1;
}
if (count == 0)
return false;
}
// For special characters
if (!((password.find("@") != std::string::npos) ||
(password.find("#") != std::string::npos) ||
(password.find("!") != std::string::npos) ||
(password.find("~") != std::string::npos) ||
(password.find("$") != std::string::npos) ||
(password.find("%") != std::string::npos) ||
(password.find("^") != std::string::npos) ||
(password.find("&") != std::string::npos) ||
(password.find("*") != std::string::npos) ||
(password.find("(") != std::string::npos) ||
(password.find(")") != std::string::npos) ||
(password.find("-") != std::string::npos) ||
(password.find("+") != std::string::npos) ||
(password.find("/") != std::string::npos) ||
(password.find(":") != std::string::npos) ||
(password.find(".") != std::string::npos) ||
(password.find(",") != std::string::npos) ||
(password.find("<") != std::string::npos) ||
(password.find(">") != std::string::npos) ||
(password.find("?") != std::string::npos) ||
(password.find("|") != std::string::npos)))
return false;
if (true)
{
int count = 0;
// Checking capital letters
for(int i = 65; i <= 90; i++)
{
// Type casting
char c = (char)i;
string str1(1, c);
if (password.find(str1) !=
std::string::npos)
count = 1;
}
if (count == 0)
return false;
}
if (true)
{
int count = 0;
// Checking small letters
for(int i = 90; i <= 122; i++)
{
// Type casting
char c = (char)i;
string str1(1, c);
if (password.find(str1) !=
std::string::npos)
count = 1;
}
if (count == 0)
return false;
}
// If all conditions fails
return true;
}
// Driver code
int main()
{
string password1 = "ZHW3";
if (isValid(password1))
cout << "Valid Password" << endl;
else
cout << "Invalid Password" << endl;
string password2 = "$ZHW3" ;
if (isValid(password2))
cout << "Valid Password" << endl;
else
cout << "Invalid Password" << endl;
}