file name - "pass_g.c"
copy
#define skey 6548
long long password(char *protect, FILE *fa, char sbl)
{
long long pass, fpass = pass = 0;
short i;
for (i = 0; protect[i] != 13 && protect[i] != '\0'; i++)
{
srand((unsigned int)protect[i] * skey * i);
pass = ~pass;
pass += rand() * 2010 * rand() * i;
pass <<= (protect[i] % 10);
pass = ~pass;
pass ^= (~rand() * 867);
pass >>= (protect[i] % 10);
pass = ~pass;
pass ^= (~protect[i] * rand());
}
srand(pass % 584848);
for (i = 1; i < 5; i++, pass += (((((rand() * (long long)rand()) * 16) * skey) * 54) * i))
;
for (i = 0; protect[i] != 13 && protect[i] != '\0'; i++)
{
srand((unsigned int)protect[i] * (pass % skey) * i);
fpass = ~fpass;
fpass += rand() * 2010 * rand() * i;
fpass <<= (protect[i] % 10);
fpass = ~fpass;
fpass ^= (~rand() * 867);
fpass >>= (protect[i] % 10);
fpass += pass;
fpass ^= (~protect[i] * rand());
}
srand(fpass % 264864);
for (i = 1; i < 5; i++, fpass += (((((rand() * (long long)rand()) * 16) * skey) * 54) * i))
;
rewind(fa);
if (sbl == 'c')
{
long long temp;
fread(&temp, sizeof(temp), 1, fa);
if (temp == fpass)
{
return pass;
}
return 0;
}
else if (sbl == 'a')
{
fwrite(&fpass, sizeof(fpass), 1, fa);
}
return 0;
}
Password protection is an important feature in a DBMS to ensure the security of sensitive information. In this post, we will discuss the implementation of password protection in a DBMS using the C programming language. The password function is defined in the pass_g.c file. It takes in a character array 'protect', a file pointer 'fa', and a character 'sbl'. The 'protect' array contains the password that needs to be hashed and stored in the database file. The 'fa' file pointer points to the database file, and 'sbl' is a flag that specifies whether the password needs to be checked or added to the database file. The password function uses a hash function to generate a unique password from the input password. The hash function uses a random number generator and bitwise operations to generate the password. The generated password is then stored in the database file. When a user tries to access the database, the entered password is hashed using the same hash function and compared with the stored password in the database file. If the passwords match, the user is granted access, and if they don't match, access is denied. The data.c file uses the password function to protect the database file. The 'pass' variable is set to the return value of the password function. The 'pass' variable is then used to grant or deny access to the database file. The short data() function in the data.c file is used to add data to the database file. The function first checks if the database file has any data or not. If there is no data, it returns an error message. Otherwise, the function reads the names of the files in the database and checks if they exist or not. If any file is missing, it returns an error message. If all files exist, the function prompts the user to add data to the database file. The user enters the data, which is then written to the respective file in the database. The function then prompts the user if they want to add more data or not. If the user chooses to add more data, the function repeats the process. If not, the function returns a success message. In conclusion, password protection is a crucial feature in a DBMS to ensure the security of sensitive information. The C programming language provides powerful tools to implement password protection using hash functions and random number generators. The password function and the data.c file are examples of how password protection can be implemented in a DBMS using C.
Click on the next button for source code of next file