Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Talking to htpasswd.exe

Talking to htpasswd.exe

Scheduled Pinned Locked Moved C#
testingbeta-testinghelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Johan Martensson
    wrote on last edited by
    #1

    Can anyone see what I'm doing wrong here? All I want to do is generate a password with htpasswd.exe and it looked easy enough but it just gets stuck at ReadLine() :confused:

    ProcessStartInfo ps = new ProcessStartInfo();
    ps.FileName = Path.Combine(Application.StartupPath, "htpasswd.exe");
    ps.Arguments = "-n test";
    ps.CreateNoWindow = true;
    ps.UseShellExecute = false;
    ps.RedirectStandardInput = true;
    ps.RedirectStandardOutput = true;
    ps.RedirectStandardError = true;

    Process proc = new Process();
    proc.StartInfo = ps;
    proc.Start();

    proc.StandardInput.WriteLine("testing");
    proc.StandardInput.WriteLine("testing");

    string line = proc.StandardOutput.ReadLine();

    proc.Close();

    http://johanmartensson.se - Home of MPEG4Watcher

    H D 2 Replies Last reply
    0
    • J Johan Martensson

      Can anyone see what I'm doing wrong here? All I want to do is generate a password with htpasswd.exe and it looked easy enough but it just gets stuck at ReadLine() :confused:

      ProcessStartInfo ps = new ProcessStartInfo();
      ps.FileName = Path.Combine(Application.StartupPath, "htpasswd.exe");
      ps.Arguments = "-n test";
      ps.CreateNoWindow = true;
      ps.UseShellExecute = false;
      ps.RedirectStandardInput = true;
      ps.RedirectStandardOutput = true;
      ps.RedirectStandardError = true;

      Process proc = new Process();
      proc.StartInfo = ps;
      proc.Start();

      proc.StandardInput.WriteLine("testing");
      proc.StandardInput.WriteLine("testing");

      string line = proc.StandardOutput.ReadLine();

      proc.Close();

      http://johanmartensson.se - Home of MPEG4Watcher

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      I know nothing about 'htpasswd', but generally a ReadLine() method expects a carriage return. Did you hit return?

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      J 1 Reply Last reply
      0
      • J Johan Martensson

        Can anyone see what I'm doing wrong here? All I want to do is generate a password with htpasswd.exe and it looked easy enough but it just gets stuck at ReadLine() :confused:

        ProcessStartInfo ps = new ProcessStartInfo();
        ps.FileName = Path.Combine(Application.StartupPath, "htpasswd.exe");
        ps.Arguments = "-n test";
        ps.CreateNoWindow = true;
        ps.UseShellExecute = false;
        ps.RedirectStandardInput = true;
        ps.RedirectStandardOutput = true;
        ps.RedirectStandardError = true;

        Process proc = new Process();
        proc.StartInfo = ps;
        proc.Start();

        proc.StandardInput.WriteLine("testing");
        proc.StandardInput.WriteLine("testing");

        string line = proc.StandardOutput.ReadLine();

        proc.Close();

        http://johanmartensson.se - Home of MPEG4Watcher

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        The exe basically generates md5 hashed passwords IIRC. That can be done in code without needing that exe. Search for MD5 c# and you'll find many results. Here are a couple: http://www.spiration.co.uk/post/1203/MD5%20in%20C%23%20-%20works%20like%20php%20md5()%20example[^] http://blogs.msdn.com/csharpfaq/archive/2006/10/09/How-do-I-calculate-a-MD5-hash-from-a-string_3F00_.aspx[^]

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
        Why are you using VB6? Do you hate yourself? (Christian Graus)

        J 1 Reply Last reply
        0
        • D DaveyM69

          The exe basically generates md5 hashed passwords IIRC. That can be done in code without needing that exe. Search for MD5 c# and you'll find many results. Here are a couple: http://www.spiration.co.uk/post/1203/MD5%20in%20C%23%20-%20works%20like%20php%20md5()%20example[^] http://blogs.msdn.com/csharpfaq/archive/2006/10/09/How-do-I-calculate-a-MD5-hash-from-a-string_3F00_.aspx[^]

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
          Why are you using VB6? Do you hate yourself? (Christian Graus)

          J Offline
          J Offline
          Johan Martensson
          wrote on last edited by
          #4

          True it generates a sort of md5 hashed passwords, but htpasswd.exe is a part of Apache webserver and they use a modified version of md5.

          http://johanmartensson.se - Home of MPEG4Watcher

          1 Reply Last reply
          0
          • H Henry Minute

            I know nothing about 'htpasswd', but generally a ReadLine() method expects a carriage return. Did you hit return?

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            J Offline
            J Offline
            Johan Martensson
            wrote on last edited by
            #5

            The WriteLine adds a carriage return so that part is ok. I found what I had missed, the command-prompt needed to exit before it returned the result. So adding this before reading the output solved it:

            proc.StandardInput.WriteLine("exit");

            http://johanmartensson.se - Home of MPEG4Watcher

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups