title: fatal: remote error: CAPTCHA required - Bitbucket - Powershell Script
body: <p>I wants to checkout the branch and commit the code changes using powershell script. This powershell script will be called from c# code.</p>
  
  <p>But some times i'm getting the following issue</p>
  
  <blockquote>
    <p>fatal: remote error: CAPTCHA required Your Bitbucket account has been
    locked.  To unlock it and log in again you must solve a CAPTCHA. This
    is typically caused by too many attempts to login with an incorrect
    password.  The account lock prevents your SCM client from accessing
    Bitbucket and its mirrors until it is solved, even if you enter your
    password correctly.</p>
  </blockquote>
  
  <p>If i logout in browser and login again by entering the CAPTCHA it is working fine. But if i host my application on server and if issue occurs, Logging out and login again is not the proper fix.</p>
  
  <p>Can you please suggest good approach of handling this issue.</p>
  
  <p>My Powershell code for Cloning the branch:</p>
  
  <pre><code>param(
      [parameter(position=0)]
      [string]$checkoutDirectory,
  
      [parameter(position=1)]
      [string]$checkoutBranch
  )
  
  function CheckoutTheCode($checkoutRepoUrl, $checkoutDirectory, $checkoutBranch)
  {
      [hashtable]$Return = @{}
      try
      {
          if(Test-Path -Path $checkoutDirectory )
          {
              Remove-Item -Recurse -Force $checkoutDirectory
          }
  
          New-Item -ItemType directory -Path $checkoutDirectory
  
          # Cloning
          git clone --single-branch -b $checkoutBranch $checkoutRepoUrl $checkoutDirectory
  
          $Return.Branch = $checkoutBranch
          $Return.Directory = $checkoutDirectory
          $Return.Status = $true
          $Return.Message = "Success"
      }
      catch
      {
          $Return.Message = $Error[0].Exception
          $Return.Status = $false
      }
  
      Return $Return 
  }
  </code></pre>
  
  <p>My Powershell code for Commit changes:</p>
  
  <pre><code>param(
      [parameter(position=0)]
      [string]$checkoutDirectory,
  
      [parameter(position=1)]
      [string]$commitMessage
  )
  
  function CommitTheCode($checkoutDirectory, $commitMessage)
  {
      [hashtable]$Return = @{}
      try
      {
          cd $checkoutDirectory
          git add .
          git commit -m $commitMessage
          git push
  
          $Return.Status = $true
          $Return.Message = "Success"
      }
      catch
      {
          $Return.Message = $Error[0].Exception
          $Return.Status = $false
      }
  
      Return $Return 
  }
  
  CommitTheCode $checkoutDirectory $commitMessage
  </code></pre>