Advertisement
RoDaBaFilms

m

Jan 5th, 2020
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.IO
  2. Imports System.Net
  3. Imports System.Security.Cryptography
  4. Imports System.Text
  5.  
  6. Namespace pwned_search                                                                              ' namespace pwned_search {
  7.    Class Program                                                                                   '     internal class Program {
  8.        Public Shared Sub Main(args As String())                                                    '       private static void Main(string[] args) {   -> converted to public because program wont start otherwise
  9.            Dim argtarget = Console.OutputEncoding                                                  '           var argtarget = Console.OutputEncoding;
  10.            Console.InputEncoding = CSharpImpl.__Assign(argtarget, Encoding.UTF8)                   '           Console.InputEncoding = CSharpImpl.__Assign(ref argtarget, Encoding.UTF8);
  11.            Console.Write("Enter the password to check: ")                                          '           Console.Write("Enter the password to check: ");
  12.            Dim plaintext = Console.ReadLine()                                                      '           var plaintext = Console.ReadLine();
  13.            Dim sha As SHA1 = New SHA1CryptoServiceProvider()                                       '           SHA1 sha = new SHA1CryptoServiceProvider();
  14.            Dim Data = sha.ComputeHash(Encoding.UTF8.GetBytes(plaintext))                           '           var Data = sha.ComputeHash(Encoding.UTF8.GetBytes(plaintext));
  15.            Dim sBuilder = New StringBuilder()                                                      '           var sBuilder = new StringBuilder();
  16.            Dim loopTo = Data.Length                                                                '           var loopTo = Data.Lenght;
  17.            For i As Integer = 0 To loopTo - 1                                                      '           for (int i = 0; i <= loopTo; i++) {        
  18.                sBuilder.Append(Data(i).ToString("x2"))                                             '               sBuilder.Append(Data[i].ToString("x2"));
  19.            Next                                                                                    '           }                                      
  20.            Dim result = sBuilder.ToString().ToUpper()                                              '           Dim result = sBuilder.ToString().ToUpper();
  21.            Console.WriteLine("The SHA-1 hash of " + plaintext + " is: " + result)                  '           Console.WriteLine("The SHA-1 hash of " + plaintext + " is: " + result);
  22.            Dim url = "https://api.pwnedpasswords.com/range/" + result.Substring(0, 5)              '           var url = "https://api.pwnedpasswords.com/range/" + result.Substring(0, 5);
  23.            Dim request = WebRequest.Create(url)                                                    '           var request = WebRequest.Create(url);
  24.            Dim response = request.GetResponse().GetResponseStream()                                '           var response = request.GetResponse().GetResponseStream();
  25.            Dim reader = New StreamReader(response)                                                 '           var reader = new StreamReader(response);
  26.            Dim hashToCheck = result.Substring(5)                                                   '           var hashToCheck = result.Substring(5);
  27.            While True                                                                              '           while (true) {
  28.                Dim line = reader.ReadLine()                                                        '               var line = reader.ReadLine();
  29.                If line = Nothing Then                                                              '               if (line == null) {
  30.                    Console.WriteLine("That password was not found.")                               '                   Console.WriteLine("That password was not found.");
  31.                    Exit While                                                                      '                   break;
  32.                End If                                                                              '               }
  33.                Dim parts = line.Split(":"c)                                                        '               var parts = line.Split(':');
  34.                If parts(0) = hashToCheck Then                                                      '               if (parts[0] == hashToCheck) {
  35.                    Console.WriteLine("Password has been compromised -- DO NOT USE!")               '                   Console.WriteLine("Password has been compromised -- DO NOT USE!");
  36.                    Exit While                                                                      '                   break;
  37.                End If                                                                              '               }
  38.            End While                                                                               '           }
  39.            Console.ReadKey()                                                                       '           Console.ReadKey();
  40.        End Sub                                                                                     '       }
  41.        Private Class CSharpImpl                                                                    '       private class CSharpImpl {
  42.            Public Shared Function __Assign(Of T)(ByRef target As T, value As T) As T               '           public static T __Assign(ref T target, T value) {   --> Removed Obselete because I don't remember how that worked in VB lol
  43.                target = value                                                                      '               target = value;
  44.                Return value                                                                        '               return value;
  45.            End Function                                                                            '           }
  46.        End Class                                                                                   '       }
  47.    End Class                                                                                       '   }
  48. End Namespace                                                                                       ' }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement