<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: API &amp;quot;err_login_failed&amp;quot; in Firewall and Security Management</title>
    <link>https://community.checkpoint.com/t5/Firewall-and-Security-Management/API-quot-err-login-failed-quot/m-p/219203#M64968</link>
    <description>&lt;P&gt;Try using single quotes around the password like this:&lt;/P&gt;
&lt;P&gt;mgmt_cli login user "$LOGIN" password '$PASSWORD' &amp;gt; id.txt&lt;/P&gt;
&lt;P&gt;If that doesn't work, turn off the history expansion function (which ! is trying to access) by adding a&amp;nbsp;&lt;STRONG&gt;set +H&lt;/STRONG&gt; at the start of your script.&lt;/P&gt;</description>
    <pubDate>Sat, 29 Jun 2024 13:44:22 GMT</pubDate>
    <dc:creator>Timothy_Hall</dc:creator>
    <dc:date>2024-06-29T13:44:22Z</dc:date>
    <item>
      <title>API "err_login_failed"</title>
      <link>https://community.checkpoint.com/t5/Firewall-and-Security-Management/API-quot-err-login-failed-quot/m-p/219200#M64965</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;I am trying to run this script on my SMS expert mode:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;#!/bin/bash
 
#vriables for login
LOGIN="cpadmin"
PASSWORD="Chkp!234"
 
# Clear screen
clear
 
# Prompt for username if LOGIN is undefined
if [ -z "$LOGIN" ]; then
  read -p "Please enter your username and press Enter: " LOGIN
fi
 
# Prompt for password if PASSWORD is undefined
if [ -z "$PASSWORD" ]; then
  read -s -p "Password: " PASSWORD
fi
echo
 
# Login to the API server and save session to file id.txt
mgmt_cli login user "$LOGIN" password "$PASSWORD" &amp;gt; id.txt
 
# Check if login was successful
if [ $? -ne 0 ]; then
  echo "Login failed."
  cat id.txt
  exit 1
fi
 
# Create network objects
echo "Creating network objects"
mgmt_cli -s id.txt add network name "A-MGMT-NET" subnet "10.1.1.0" subnet-mask "255.255.255.0" comments "Management" set-if-exists true ignore-warnings true
mgmt_cli -s id.txt add network name "A-DMZ-NET" subnet "192.168.12.0" subnet-mask "255.255.255.0" comments "DMZ" set-if-exists true ignore-warnings true
mgmt_cli -s id.txt add network name "A-INT-NET" subnet "192.168.11.0" subnet-mask "255.255.255.0" comments "Internal" set-if-exists true ignore-warnings true
mgmt_cli -s id.txt add network name "A-WIFI-NET" subnet "192.168.13.0" subnet-mask "255.255.255.0" comments "WiFi" set-if-exists true ignore-warnings true
 
# Logout
mgmt_cli -s id.txt logout
 
echo "Script execution completed."&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am getting this error:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Login failed.
code: "err_login_failed"
message: "Authentication to server failed."&lt;/LI-CODE&gt;
&lt;P&gt;if I try to login from expert mode only with this command:&lt;/P&gt;
&lt;LI-CODE lang="ruby"&gt;mgmt_cli login user admin password CPL@b8110&lt;/LI-CODE&gt;
&lt;P&gt;I get this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;[Expert@CPSMS:0]# mgmt_cli login user admin password CPL@b8110
uid: "ba1910a5-ab62-4eff-88d5-18fbabf73808"
sid: "SF_3IDzUm3KtLI_pksoPSliBVxkXCQ4N9SZAIz5MEAo"
url: "https://127.0.0.1:443/web_api"
session-timeout: 600
last-login-was-at:
  posix: 1719657035894
  iso-8601: "2024-06-29T12:30+0200"
api-server-version: "1.8"
user-name: "admin"
user-uid: "725333a3-ac40-46b5-8b44-ef17a83f8da3"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have done what is in sk127572 but still have same problem!&lt;/P&gt;
&lt;P&gt;Is there any way to run the script from Powershell?&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jun 2024 13:01:01 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Firewall-and-Security-Management/API-quot-err-login-failed-quot/m-p/219200#M64965</guid>
      <dc:creator>Moudar</dc:creator>
      <dc:date>2024-06-29T13:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: API "err_login_failed"</title>
      <link>https://community.checkpoint.com/t5/Firewall-and-Security-Management/API-quot-err-login-failed-quot/m-p/219201#M64966</link>
      <description>&lt;P&gt;Add &lt;STRONG&gt;set -x&lt;/STRONG&gt; to line 2 of your script so you can see precisely how the variables are being substituted.&amp;nbsp; I suspect the "!" symbol in the password is not being quoted correctly, if you take the "!" out of the password and make it Chkp234 does it work?&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jun 2024 13:31:00 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Firewall-and-Security-Management/API-quot-err-login-failed-quot/m-p/219201#M64966</guid>
      <dc:creator>Timothy_Hall</dc:creator>
      <dc:date>2024-06-29T13:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: API "err_login_failed"</title>
      <link>https://community.checkpoint.com/t5/Firewall-and-Security-Management/API-quot-err-login-failed-quot/m-p/219202#M64967</link>
      <description>&lt;P&gt;Now it is working,&lt;/P&gt;
&lt;P&gt;It was the "!" in the password the problem&lt;/P&gt;
&lt;P&gt;I have tested 'Chkp!234' but still problem&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jun 2024 13:35:50 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Firewall-and-Security-Management/API-quot-err-login-failed-quot/m-p/219202#M64967</guid>
      <dc:creator>Moudar</dc:creator>
      <dc:date>2024-06-29T13:35:50Z</dc:date>
    </item>
    <item>
      <title>Re: API "err_login_failed"</title>
      <link>https://community.checkpoint.com/t5/Firewall-and-Security-Management/API-quot-err-login-failed-quot/m-p/219203#M64968</link>
      <description>&lt;P&gt;Try using single quotes around the password like this:&lt;/P&gt;
&lt;P&gt;mgmt_cli login user "$LOGIN" password '$PASSWORD' &amp;gt; id.txt&lt;/P&gt;
&lt;P&gt;If that doesn't work, turn off the history expansion function (which ! is trying to access) by adding a&amp;nbsp;&lt;STRONG&gt;set +H&lt;/STRONG&gt; at the start of your script.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jun 2024 13:44:22 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Firewall-and-Security-Management/API-quot-err-login-failed-quot/m-p/219203#M64968</guid>
      <dc:creator>Timothy_Hall</dc:creator>
      <dc:date>2024-06-29T13:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: API "err_login_failed"</title>
      <link>https://community.checkpoint.com/t5/Firewall-and-Security-Management/API-quot-err-login-failed-quot/m-p/219613#M64969</link>
      <description>&lt;P&gt;Unfortunately, that won't help. &amp;nbsp;Single quotes in Bash prevents variable interpolation. &amp;nbsp;The ! will need to be escaped and not quoted in any manner, or, preferably, don't use that kind of special character as a password (this is why.. also don't use these either:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;% * @ # $ ^ &amp;amp; ( ) ' " &amp;lt; &amp;gt; / &lt;/LI-CODE&gt;
&lt;P&gt;Each of these have some special meaning in Bash and should be avoided. &amp;nbsp;Bash is finicky about quotes and special characters and escapes:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[Expert@cpmgmt:0]# PASSWORD="Foo\!Bar"
[Expert@cpmgmt:0]# echo $PASSWORD
Foo\!Bar
[Expert@cpmgmt:0]# PASSWORD=Foo\!Bar 
[Expert@cpmgmt:0]# echo $PASSWORD
Foo!Bar
&lt;/LI-CODE&gt;
&lt;P&gt;You can prompt for a password with a special character just fine:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[Expert@moon:0]# read -s -p "Password: " PASSWORD;echo
Password: 
[Expert@moon:0]# echo "$PASSWORD"
FOO!BAR
&lt;/LI-CODE&gt;
&lt;P&gt;It's best to just avoid the whole ordeal, tho.&lt;/P&gt;
&lt;P&gt;Besides, you never know what the back-end developer is doing to your input string, either.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_frowning_face:"&gt;🙁&lt;/span&gt; &amp;nbsp;You know those apps... the ones that do a SQL query somewhere and you throw in a "%" character. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Such as this little gem that's always good for a laugh:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[Expert@cpmgmt:0]# FOO="3/0"
[Expert@cpmgmt:0]# if (( $FOO )); then echo bar; fi
-bash: 3/0  : division by 0 (error token is "0  ")
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 18:57:03 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Firewall-and-Security-Management/API-quot-err-login-failed-quot/m-p/219613#M64969</guid>
      <dc:creator>Duane_Toler</dc:creator>
      <dc:date>2024-07-03T18:57:03Z</dc:date>
    </item>
  </channel>
</rss>

