PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 12, 2022

[FIXED] How one may check whether credential manager in Git has password stored for a given domain?

 September 12, 2022     cross-platform, git     No comments   

Issue

Git can be configured to remember passwords.

How one may check whatever given domain has stored password?

I found on https://git-scm.com/docs/git-credential one of available APIs.

For example, assuming that we are interested in GitHub credentials and username is stored on gitconfig we may run

git credential fill
protocol=https
host=github.com
<empty line>

that will return password if it is available in the credential cache. Unfortunately, it will lock (and ask the user for specifying password) if password is not available, what makes it unsuitable for a script.

https://git-scm.com/docs/gitcredentials seems to not have any info useful to solve this.

To avoid XY problem: I have a script that is supposed to automatically push commits from one of the repositories. It can wait with push until user authenticated and GitHub credential cache remembered a password.

I am strongly preferring cross-platform solutions (I will use it on Linux but I prefer to not rewrite my git setup on starting to use other OS).


Solution

The Microsoft GCM (Git Credential Manager) includes a non-interactive mode support.

More generally (independent of the OS), a custom credential manager would always include the commands:

  • get
  • store
  • erase

A get followed by a grep should be enough to confirm if a domain has a password registered in that credential helper.

More precisely (and cross-platform solution):

printf "protocol=https\nhost=github.com"| git credential-manager-core get

Assuming your git config credential.helper returns "manager-core".
If it returns 'xxx' (anything else):

printf "protocol=https\nhost=github.com"| git credential-xxx get

Replace xxx by your value.



Answered By - VonC
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing