I am wanting to convert this code to use in a VB app form but not sure where to start, I am wanting to use an app instead of a console. Any help would be appreciated
Code:
namespace pwned_search
{
internal class Program
{
private static void Main(string[] args)
{
var argtarget = Console.OutputEncoding;
Console.InputEncoding = CSharpImpl.__Assign(ref argtarget, Encoding.UTF8);
Console.Write("Enter the password to check: ");
string plaintext = Console.ReadLine();
SHA1 sha = new SHA1CryptoServiceProvider();
var data = sha.ComputeHash(Encoding.UTF8.GetBytes(plaintext));
var sBuilder = new StringBuilder();
for (int i = 0, loopTo = data.Length - 1; i <= loopTo; i++)
sBuilder.Append(data[i].ToString("x2"));
string result = sBuilder.ToString().ToUpper();
Console.WriteLine($"The SHA-1 hash of {plaintext} is: {result}");
string url = "https://api.pwnedpasswords.com/range/" + result.Substring(0, 5);
var request = WebRequest.Create(url);
var response = request.GetResponse().GetResponseStream();
var reader = new StreamReader(response);
string hashToCheck = result.Substring(5);
while (true)
{
string line = reader.ReadLine();
if (line == null)
{
Console.WriteLine("That password was not found.");
break;
}
var parts = line.Split(':');
if (parts[0] == hashToCheck)
{
Console.WriteLine("Password has been compromised -- DO NOT USE!");
break;
}
}
Console.ReadKey();
}
private class CSharpImpl
{
[Obsolete("Please refactor calling code to use normal Visual Basic assignment")]
public static T __Assign<T>(ref T target, T value)
{
target = value;
return value;
}
}
}
}