php / pecl-networking-ssh2

Bindings for the libssh2 library
http://pecl.php.net/package/ssh2
Other
51 stars 58 forks source link

ssh2_auth_password Password parameter does not work as expected #58

Closed auth1299 closed 1 year ago

auth1299 commented 2 years ago

I'm using https://pecl.php.net/package/ssh2 module in PHP. The password parameter is not working as intended.

This Works: <?php $connection = ssh2_connect('shell.example.com', 22);

if (ssh2_auth_password($connection, 'username', 'secret')) { echo "Authentication Successful!\n"; } else { die('Authentication Failed...'); } ?>

but if I put that code into a function and pass the password into the function ssh2_connect() authentication will fail. Password will only work if I manually supply it in the code. My use case is pulling the password from a database and passing it into a custom function parameter and then pass it to ssh2_connect().

I had the issue on windows PHP 7.4 using the 1.2 SSH2 module I then upgraded to version PHP 8.1 and now using 1.3 SSH2 module on windows. I get the same behavior on both versions.

langemeijer commented 2 years ago

I don't understand, there are some factual errors in the issue you are describing. ssh_connect() has no password parameter.

Can you share both a working and non-working minimal code snippet?

auth1299 commented 2 years ago

The code snippet does not show for some reason in the above comment.

I meant to say ssh2_auth_password() function.

It seems that if I pull the password from a database and passed it to ssh2_auth_password() function, it will not authenticate but if I hardcode the password as a string into the ssh2_auth_password() function, it works. I've made sure to format the database string as a (string)$password. Is there a way to debug exactly what the ssh2_auth_password() is doing? I can't seem to find any documentation any where on how to enable debug logging for ssh2_auth_password().

langemeijer commented 2 years ago

Can you reproduce the issue if you hard-code the password in the file, but use concatenation to build the string? eg:

ssh2_auth_password($session, 'user' . 'name', 'welcome' . '123');
langemeijer commented 1 year ago

I'm happy to work forward with you in fixing this issue, but you are giving me nothing to work with. For now I can only follow Occam's razor and assume you've made some trivial error in your code somehow.

Please provide me with snippet of code that allows me to repeat your issue and we can move further.