The IDEcrashers Guide To Handling Salted Hash Algorithms for User Credentials in a Terminal Environment
Ω-:[KodaKing]:-Ω
The System.Security library maintains the System.Security.Cryptography nested class.
When hashing encryptions from user input, this can assist in more descrete authorization handling.
When dealing with the Hash support it is necessary to determine the algorithm of choice.
I will be using SHA-512 enencryption.
For this lesson, I will stick to simply accessing an unprotected text file in /Documents for both the Username hash-table and the Password has-table.
Within a Command Line interface we should first prompt the user for desired activity.
After we have set for the input, we can handle a new User Key-Pairing and output the pair to a text document.
First we need to recieve out UTF-8 Username input and Password input from our new User.
For encryption of the SHA512 algorithm, we will create a new SHA512 instance and name the method shaWoah to be follow a new Managed function call.
Now convert the bytecode to a SHA512 hash.
Having completed the first encryption hash, we can implement the same process for our password.
After we have encrypted both the Username and Password, we may now transfer them to desired text file locations.
You can determine any path for your text file.
I will be converting my SHA 512 hash to a base64 string to provide a textual value.
Now, we can simply say nice words to the User.
For returning Users we will need to parse their input and authenticate.
Once again, to hash the encryption we must convert to bytecode from our UTF-8 input string.
To check the index of our key-pair, we will implement the StreamReader method and load our text file of Hashes to it.
With a boolean operation we can check the relation of the indexes.
At this point, we will save the index location of the individual input credentials.
Now we get to our final Authentication.
By passing the boolean we can validate the key-pair.
If we are unable to verify the Username and Password combination, we will need to alert the User and determine a new life-cycle path.
For such a task, I will display an error message to the console and relay back to the program's initialization.
With Authentication completed we get to deeper and more amusing things.
Ω-:[KodaKing]:-Ω
The System.Security library maintains the System.Security.Cryptography nested class.
When hashing encryptions from user input, this can assist in more descrete authorization handling.
Code
using System;
using System.Console;
using System.Collections.Generic;
using System.Security;
using System.Security.Cryptography;
using System.Linq;
using System.IO;When dealing with the Hash support it is necessary to determine the algorithm of choice.
I will be using SHA-512 enencryption.
For this lesson, I will stick to simply accessing an unprotected text file in /Documents for both the Username hash-table and the Password has-table.
Within a Command Line interface we should first prompt the user for desired activity.
Code
System.Console.WriteLine("Welcome!");
System.Console.WriteLine("Are You A New User Or Returning?");
string input1 = System.Console.ReadLine();After we have set for the input, we can handle a new User Key-Pairing and output the pair to a text document.
First we need to recieve out UTF-8 Username input and Password input from our new User.
Code
byte[] UsrData = Encoding.UTF8.GetBytes(Usr);
byte[] shaHash;
byte[] shaPwdHash;Now convert the bytecode to a SHA512 hash.
Code
SHA512 shaWoah = new SHA512Managed();
shaHash = shaWoah.ComputeHash(UsrData);Having completed the first encryption hash, we can implement the same process for our password.
Code
byte[] PwdData = Encoding.UTF8.GetBytes(Pwd);
SHA512 shaYou = new SHA512Managed();
shaPwdHash = shaYou.ComputeHash(PwdData);After we have encrypted both the Username and Password, we may now transfer them to desired text file locations.
You can determine any path for your text file.
I will be converting my SHA 512 hash to a base64 string to provide a textual value.
Code
string InMy64 = Convert.ToBase64String(shaHash);
System.Console.WriteLine(InMy64);
string OnThat11 = Convert.ToBase64String(shaPwdHash);
System.Console.WriteLine(OnThat11);
using (StreamWriter outputUsr = new StreamWriter(@"C:\Users\Naye\Documents\Usrnames.txt", true))
{
outputUsr.WriteLine(InMy64);
}
using (StreamWriter outputPass = new StreamWriter(@"C:\Users\Naye\Documents\Pwds.txt", true))
{
outputPass.WriteLine(OnThat11);
}Now, we can simply say nice words to the User.
Code
System.Console.WriteLine("Your Information Has Been Written To The File System!");For returning Users we will need to parse their input and authenticate.
Code
System.Console.WriteLine("Welcome! Please Input Your Username: ");
string Usr = Console.ReadLine();
System.Console.WriteLine("Thank You! Please Input Your Passkey Information: ");
string Pwd = Console.ReadLine();Once again, to hash the encryption we must convert to bytecode from our UTF-8 input string.
Code
byte[] UsrData = Encoding.UTF8.GetBytes(Usr);
byte[] shaHash;
byte[] shaPwdHash;
SHA512 shaWoah = new SHA512Managed();
shaHash = shaWoah.ComputeHash(UsrData);
byte[] PwdData = Encoding.UTF8.GetBytes(Pwd);
SHA512 shaYou = new SHA512Managed();
shaPwdHash = shaYou.ComputeHash(PwdData);
string InMy64 = Convert.ToBase64String(shaHash);
string OnThat11 = Convert.ToBase64String(shaPwdHash);To check the index of our key-pair, we will implement the StreamReader method and load our text file of Hashes to it.
With a boolean operation we can check the relation of the indexes.
Code
int userindexglobal = 0;
using (StreamReader usrread = new StreamReader(@"C:\Users\Naye\Documents\Usrnames.txt", true))
{
string contents = usrread.ReadToEnd();
if (contents.Contains(InMy64))
{
System.Console.WriteLine("Thank You!");
goto UsrIndex;
}
else
{
Console.WriteLine("We're Sorry, Your Username Was Not Found To Be Valid.");
goto LogIn;
}At this point, we will save the index location of the individual input credentials.
Code
UsrIndex:
userindexglobal = contents.IndexOf(InMy64);
goto Pass;
}
Pass:
int passindexglobal = 0;
bool usrAuth = true;
using (StreamReader pwdread = new StreamReader(@"C:\Users\Naye\Documents\Pwds.txt", true))
{
string contents = pwdread.ReadToEnd();
if(contents.Contains(OnThat11))
{
System.Console.WriteLine("We Appreciate You Following These Security Formalities. Thank You, Once Again!");
goto PassIndex;
}
else
{
Console.WriteLine("We're Sorry Your Passkey Did Not Authorize.");
goto Start;
}
PassIndex:
passindexglobal = contents.IndexOf(OnThat11);
goto Auth;
}By passing the boolean we can validate the key-pair.
Code
Auth:
bool passAuth = true;
bool doesit = usrAuth == passAuth;
if (doesit == true && userindexglobal==passindexglobal)
{
goto MainSubLoop;
}If we are unable to verify the Username and Password combination, we will need to alert the User and determine a new life-cycle path.
For such a task, I will display an error message to the console and relay back to the program's initialization.
Code
else
{
Console.WriteLine("Authorization Did Not Occur. Looping Cycle.");
goto Start;
}With Authentication completed we get to deeper and more amusing things.
