Graphical P4 Login

Today I ran into an interesting little problem. Without going into too much detail (and too keep from getting my ass into trouble at work) I ran into a situation where it would be really nice to be able to log into P4 through a batch file. The issue was, I didn't want to have to store an MD5 hash of a password, or a clear text version of the password on the client's machine. What I really wanted was a simple, GUI version of 'P4 login -a'. But without the console based prompting for a user's password. There are options for doing it, but none of them felt satisfactory to me. For those curious, options include:

building a batch file that is essentially:




Not a fan of this method.

Or storing an MD5 Hash and passing that through a la: http://kb.perforce.com/UserTasks/ConfiguringP4/AvoidingTheP..rdInWindows.

A google search came up empty. This surprised me as I would have thought something like this would have been a common need. Who knew?

So, I figured that I'd just write my own. I mean, how hard can it be? All you have to do is pass in the password on the command line, right?

The other thing is that I want whatever app I create to be nearly stand-alone. The only thing that it should rely on is P4.exe. I don't want it to hook into the P4 API, or any other nonsense (being dependent on P4.exe is bad enough).

Wrong. P4 login doesn't work that way. You can't pass in the password, it has to come through Standard Input. Whut-oh.

Well, it's not that bad, actually. Using CSharp, it's just a matter of using the Process object and hooking into the StdInput. Surprisingly easy, once you find it.

The form is a simple layout. I don't even ask for a username (easy enough for you, dear reader, to add). But for my case, all I need is the password. So a quick mock-up of the GUI would look like this:
The Window Mockup

So, what's the code that does all this funky stuff?



Again, the big thing here is to use a streamwriter object as the redirection for STDIN. At that point, it a stream and you can do pretty much anything you want to.

Additionally, I've archived the project. You can access it here

Comments

Popular Posts