Home > Software Deployment > Perforce auto login using md5 hash (p4v and cli)

Perforce auto login using md5 hash (p4v and cli)

December 14, 2011 Leave a comment Go to comments

A coworker of mine showed me a cool way of avoiding having to type your password each time you log into Perforce: An md5 of your password stored in an environment variable, or an .ini file if your using the command line.

1. in p4v, click Connection > Edit Current Workspace. Make a note of your ‘Root’. Mine is C:\depot\

2. Navigate to your ‘Root’ and create an file P4.ini

Mine looks like this:

# This is to tell the sd client what server and port to use
p4PORT=perforce:1985
P4HOST=a-box
P4USER=a-cool-guy
p4CLIENT=a-nskitch_hisWorkspace
P4PASSWD=(Get this from step 3)

2a: If you’re doing this for p4v, just create these as environment variables instead.

3. Go to one of the following websites and generate the md5 hash of your password and place it in your .ini file for the P4PASSWD value.
http://www.miraclesalad.com/webtools/md5.php
http://www.adamek.biz/md5-generator.php

  • Note: The md5 hash MUST BE ALL CAPITALIZED. It took a bit of Perforce documentation reading to realize what my problem was.
  • Note, instead of an .ini file, you can create an environment variable called P4PASSWD. I chose to use an .ini because at my work we connect to four different depots using different accounts. Because you can only have one environment variable, the .ini allows you to connect to as many depots as you want as long as the .ini file is placed in the root of your workspace.  Here‘s a good description of the various ways to set these variables and their search order.

4. Add a System Environment variable named P4CONFIG with a value of p4.ini .  This is how Perforce knows to look for our p4.ini file.

 

You can verify that perforce is finding your p4.ini file by typing from the command line: p4 set. You should see the output of this command matches the contents of your p4.ini file.

Result:

Each time you open Perforce, you will not be prompted for your password! Sweet!

Advertisements
  1. June 4, 2012 at 3:00 pm

    I have multiple servers i connect to so is there a way this could work at the project level or only at the workspace level?

    • Nick Skitch
      June 4, 2012 at 3:41 pm

      As far as I know, that should work fine. Each servers document Root folder is going to be a different location on disk.. that allows you to use multiple p4.ini files.

  2. bradym
    September 25, 2013 at 12:40 am

    Thanks for the write up. I’ve been trying to figure this out but somehow missed that you have to put the config file in the workspace root. Once I did that it worked perfectly.

    And a tip: there’s an easier way to get your password hash: once you’ve logged into perforce, look at p4tickets.txt in your home directory (C:\Users\username on windows 7) and you’ll see something like this:

    127.0.0.1:1818=username:BEB5111956BD118BB6CA93E4C394D007

    That last part is your password hash.

  3. October 24, 2013 at 6:58 am

    Thanks for the tip, it really improved the daily login routine !

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: