debug pdo connection username when windows authentication logon used - php

I tried new connection via:
$conn = new PDO("sqlsrv:server=SERVERNAME;database=DBNAME;MultipleActiveResultSets=false", "username", "password");
and it did not work, however when I remove the username and password it works fine.
username is the same as my windows login, I tried multiple combinations as DOMAIN\username or username#domain.com etc, nothing works. However when username and password are not present, then it connects fine.
The error is:
SQLSTATE[28000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'username'.
so to my question, in order to debug the problem.
Is it possible to check what username is used when automatic authentication is used after the login succeed?
EDIT: so once upon login without username and pass i tried:
Select name FROM DBNAME.sys.syslogins
and it gave me "DOMAIN\USERNAME"
I have tried that several times even before, but still same error :(
EDIT2: is it in db loginlist authorization? I have tried SQL Studio to log in via Windows authentication - works fine, however when i sqich to SQL server authentication and use the correct username and password, it gives me same error again, like the username is not existing anymore...

So at the end, I have found out that one account can not be set to log in via SQL authentication and windows authentication as well. So If I can login via windows authentication (no username and pass entered), then only way is to create new account with same username and set it as SQL Authentication upon Login.
Please correct me if Im wrong (and mainly someone who can test otherwise - because i have found security setting to the account which says "SQL Server and Windows Authentication mode" which is active anyway but doesnt work, and according to our database admin, this setting is not what its for)

Related

Laravel with LDAP

I'm trying to connect to OpenLDAP using Laravel. All I did was follow the https://ldaprecord.com/docs/laravel/v1/ tutorial. But this tutorial only connect to trial LDAP. I need to connect to my localhost openLDAP.
I'm using these .env configs:
LDAP_LOGGING=true
LDAP_CONNECTION=default
LDAP_HOST=127.0.0.1
LDAP_USERNAME=null
LDAP_PASSWORD=null
LDAP_PORT=10389
LDAP_BASE_DN="dc=example,dc=com"
LDAP_TIMEOUT=5
LDAP_SSL=false
LDAP_TLS=false
Ldap connection test comes successful. But when I try to login using UI, I get that credentials are wrong. i only have created one user so cant be wrong.
From the documentation: "To connect to your LDAP server, a username and password is required to be able to query and run operations on your server(s)."
So you need to enter a (proxy) username and password at the LDAP_USERNAME and LDAP_PASSWORD prompts in order for the application to be able to interact with the LDAP server.
My guess is that you need to enter the user DN and not the short username: uid=username,ou=people,dc=example,dc=com or similar

PHP script cannot connect to MYSQL database

I have a straight forward script that is trying to connect to a MySQL database.
When I run the script, I get the error:
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES) in C:\xampp\htdocs\ShopSite\submitReg.php on line 16
Failed to connect.
The connection code is:
$server="127.0.0.1";
$db="shop";
$user="root";
$password="";
$conn=mysqli_connect($server,$user,$password,$db) or die("Failed to connect");
I can connect to phpMyAdmin and edit the database on there just fine. I am using XAMPP and running it locally.
When I go to user accounts, it says there is no password for root. I looked in the config file and there are no passwords set. I haven't set a password for anything.
I haven't went in and fiddled with settings, or created any new accounts. It was working fine (never used to get this problem), then it just started with this. I reinstalled XAMPP, still giving me this issue.
I don't get why it says using password "YES".
I've been at this for hours trying to fix it. I've looked through lots of threads. Not all necessarily apply to me, as I am running it locally, and haven't been going in and making new user accounts. Everything is default.
Before I reinstalled, I tried creating a new user account and giving it the necessary privileges. I gave it a password too. Didn't work.
I don't get why it is doing this, and am not knowledgeable enough to fix it myself. Any help is much appreciated, so that it can go back to connecting.
change
$server="127.0.0.1";
by
$server="localhost";
I used XAMPP for a while and it worked quite good for me,
i think the default password for your mysql server is not set to '', so i guess
if you change the root password and try accessing your database using the new password, it should work.
Updating the root password
To update the root use password, you have to go by these steps:
Open the XAMPP Control Panel
Click on the MySQL button
After the MySQL console has loaded, execute this query:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('pass');`
After that, change the $password variable to the new password which
is in this case pass
Adding a new user
You could also add a new user by executing this query:
GRANT ALL PRIVILEGES ON *.* TO 'new-user'#'localhost' IDENTIFIED BY 'password';
While the username is new-user and the password is password.
I hope this helps.

MySQL - access denied until I connect via Workbench or CLI

I'm having issues with intermittent connection issues from my localhost PHP site to my localhost MySQL DB. It gives me back Access Denied for 'user'#'localhost' (using password: YES) as is typical for a wrong password. I tested to make sure it wasn't anything particular, and I could get it with root, so I was confused. I even set up a 127.0.0.1, a localhost and a % account with the same username and password. None of them worked, but root worked just fine. That's been my biggest confusion - 'root' working with no issues, but this new user not working at all.
I've looked through so many of the problems (see below) and issues laid out on SE and other forums relating to Error 1045, Access Denied and all variants, and most boil down to a misspelling, or a typo, or something of that nature. I've copy and pasted every relevant string around all of my code, so that's not the issue. I don't have an anonymous user, so that's not the issue. There's no DNS issues, it's localhost and I've tried every iteration of that.
The issue comes from what solves the issue for me. If I open a connection to the DB using the new account via MySQL Workbench or CLI, suddenly the webpage will work with no issues, connecting via the new account with no problems. But if I run the script that changes the new account information whatsoever, even if I change nothing, and reload the page, it will deny the access again until I open that connection up again via MySQL Workbench or the CLI.
It works without fail, every single time. I have no idea what's going on - does the account need to be logged into via CLI or Workbench before they can be used via PHP? Or is there something more I am missing here?
PHP Code
$servername='localhost';
$username='website';
$password='password';
$database='db_1';
$conn=new mysqli($servername, $username, $password, $database);
if($conn->connect_error) die("connection failed");
MySQL Credentials Creation
create user website#'localhost' identified by 'password';
grant SELECT, INSERT, DELETE on db_1.* to 'website'#'localhost';
A few of the SO questions that didn't help:
MySQL - Access denied for user
access denied for user # 'localhost' to database ''
"Connect failed: Access denied for user 'root'#'localhost' (using password: YES)" from php function
EDIT 1:
I am running a WAMP stack on a local computer. I have my firewall open for port 3306 (the port MySQL is listening on). I am not using CPanel (I think that's what it's called anyways). And I just tested and it doesn't work with root either until I go ahead and recreate a new connection to the DB via the CLI or Workbench.
The error it's giving back also includes this, but I've never had this come up as I've never tried to install OpenSSL on either before: mysqli::__construct(): PHP was built without openssl extension, can't send password encrypted in [file]. But this goes away as soon as I make the connection via the CLI (no fancy tags or anything, so I don't think I'm using SSL) or via Workbench.
Edit 2: The rabbit hole went deeper and then stopped but I'm still confused as to how to configure my set up properly to avoid it in the future/fix it to be more secure. The solution (which I can't put up as my own, so if one of you wants to explain and then claim this, go for it - I'll accept it) was to go back to my MySQL server and reconfigure the Authentication Method to not use the Strong Password Encryption and instead opt for the Legacy Authentication Method. If someone could explain how to make my PHP compatible with the newer authentication method (I haven't looked yet but will be after I post this) I would be grateful.
The solution was to go back to my MySQL server and reconfigure the Authentication Method to not use the Strong Password Encryption and instead opt for the Legacy Authentication Method.

How to get client username php - only getting localhost username

Hi I am using the code below to retrieve client username on my website but it only works for me on localhost, other people connected remotely to the file its just finding nothing with no errors or anything.
exec("wmic /node:$_SERVER[REMOTE_ADDR] COMPUTERSYSTEM Get UserName", $user);
echo($user[1]);
What is the problem ?
For a remote system you may need to send administrator credentials, e.g.
exec("wmic /node:$_SERVER[REMOTE_ADDR] /user:administrator /password:mypassword COMPUTERSYSTEM Get UserName", $user);
echo($user[1]);
I'd also research if safe to trust REMOTE_ADDR and use it in this way with wmic.
If you are using IIS and looking to get the remote users AD username, this may help: Can you get a Windows (AD) username in PHP?

phpmyadmin connecting to database

I have a website that connects to a database and retrieves page content and all works fine. However, I then use the same database connection to connect to and retrieve user details for logging in to my site (2 tables but both in same database). However, I get the following error message when doing this.
Warning: mysql_query() [function.mysql-query]: Access denied for user 'username'#'localhost' (using password: NO)
The hint is in "using password NO" There is no password being sent - in fact it is only using username#localhost as the username so it looks like you don't have your credentials configured properly.
Check config.inc.php - http://wiki.phpmyadmin.net/pma/Configuration_storage
Well it's says that your password is not correct and that you haven't gained access. Can you please upload a code here ? if you're using localhost, then the username should be root .. try to change it and leave the password field empty for now.

Categories