Why isn't psycopg2.connect checking the password? - postgresql

I'm playing with psycopg2 for the first time today, and I'm trying to understand how passwords work... I have a test script which drops a table, recreates the table, adds a row, and prints the row. My question is why does the connect command work whether or not I give it a correct password? e.g. this line:
conn = psycopg2.connect(database="mydb",host="localhost",port=5432,user="amos",
password="asdf")
and this line:
conn = psycopg2.connect(database="mydb",host="localhost",port=5432,user="amos",
password="asdf123")
unexpectedly do the same thing, and the rest of the script completes with no error. Clearly only one of those lines should work regardless of what the password actually is. As expected, I do get an error if I try a user="amos123", since that user doesn't exist. If it matters, my PostgreSQL was installed with Postgres.app.

After some research, I discovered that login criteria are specified in a file called pg_hba.conf, which in my installation by default has this line:
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 trust
which according to this the trust value means it doesn't check passwords. I guess that was unintuitive to this newb because if that behavior was what I wanted, I wouldn't have set passwords in the first place. I'm posting it here to save future googlers some time.

Related

how to reset the keyring of stored email password in Visual Studio Code in Windows with yagmail?

I'm using knockknock to email myself when training a model is complete.
I am using VS Code. The first time I
use the #email_sender(recipient_emails=email_address), it prompted me for a password, which I typed in the wrong one.
Unfortunately VS Code stores the password in a keyring, and I cannot figure out how to reset this value. How to reset the password stored in the keyring?
VS Code apparently only prompts you for your email password the FIRST time you use knockknock's #email_sender decorator, but every time after that, VS Code does NOT prompt for the password, so I have no way to adjust/fix the password to the right one.
How to reset the stored password in the keyring? I think knockknock uses the yagmail library
It took me a while but I eventually found the solution:
import keyring
# to show the set password
print(keyring.get_password("yagmail", "your_email"))
# to change to the current password
keyring.set_password("yagmail", "your_email", "new_password")

Powershell - The Parameter "XXXX" is declared in parameter-set "__AllParameterSets" multiple times

First of all, i'm sorry if this question has been posted before.
I couldn't seem to find and answer we could work with, so here goes..
Backstory:
Every 90 days all password of the NT-accounts will expire.
The office staff gets a notification when they're signing in into Windows 10.
However our iPad users (salesmen and technicians who are on the road) don't get a notification about the expiration.
They use an app which requires a NT-account to sign into our sales system.
Now we've found a Powershell script which would e-mail the user about the expiration of his password, but unfortunately we keep getting the following error:
"The parameter "testing" is declared in parameter-set "__AllParameterSets" multiple times."
As we do not have any Powershell programming skills, we have no idea what going wrong in the script.
Could you guys help us?
The following script is being used (ofcourse edited with our SMTP server and e-mail addresses).
https://gallery.technet.microsoft.com/scriptcenter/Password-Expiry-Email-177c3e27
Much obliged :-)
the code you 1st linked to never, EVER mentions parameter sets. not once. [grin]
the code in your 2nd link mentions it # 106 = __AllParameterSets.
that it IS NOT a parameter set attribute, but is some "other thing". it looks like a call to something in python.
there is no other mention anywhere in your linked code of that __AllParameterSets thing.
so, the fix is to remove it OR to rename it something that does not use a powershell keyword. [grin]

how to change mysql_query to mysqli_guery

I am using in a script mysqli_query but i think there is something wrong with the syntaxes. The script did work before, but changing everything form mysql_query to mysqli_query, data is not put anymore correct in the database.
This was the original query:
mysql_query( "INSERT INTO download_manager (SET filename='".mysqli_real_escape_string($_GET['file'])."'),
ON DUPLICATE KEY UPDATE downloads=downloads+1");
I changed it with mysqli_query this way:
mysqli_query($link, "INSERT INTO download_manager (SET filename='".mysqli_real_escape_string($_GET['file'])."'),
ON DUPLICATE KEY UPDATE downloads=downloads+1");
Can someone tell me what i did wrong?
Update:
My connection looks like this:
$link = #mysqli_connect($db_host, $db_user, $db_pass, $db_database) or die ("Error " . mysqli_error($link));
mysql_set_charset('utf8');
Ensure that the handle stored in $link was generated from a call to mysqli_connect and not mysql_connect:
http://php.net/manual/en/function.mysqli-connect.php
If that fails, check for an error:
die(mysqli_error($link))
Troubleshooting
The mysql and mysqli PHP modules are distinct, and you can't mix functions between the modules.
Enable error reporting to ensure you are able to see useful error messages.
Ensure the database credentials and connection details are valid.
Use mysqli_error after mysqli_xxx function calls to detect issues within the mysqli module.
Use the # token sparingly to avoid hiding useful errors.

Create event log entry with powershell and fill in user

I need to create entry to Windows Event Log (e.g. application log). I know how to do all the stuff beside filling in the user who performed the action.
Example:
I need to create a script, that writes some message into application log. I used this tutorial, which worked fine: http://blogs.technet.com/b/heyscriptingguy/archive/2013/06/20/how-to-use-powershell-to-write-to-event-logs.aspx
But I am not able to influence the "user". When adding entry in windows log, it always fills "User: N/A".
Any idea how to pass "user" argument to the "write-eventlog" cmdlet?
Thank you for your help.
Even though (as far as I'm aware) Write-EventLog does not provide an option to write directly to the "User" field, you have two workarounds:
Use built-in standalone exec "EventCreate.exe" (type in eventcreate /? to see the manual)
This one does support providing the username field. I'm not sure, but it may require a password for that user too.
Second workaround would be to pass $env:USERNAME to the "message" field of Write-EventLog. This way you will still obtain the environment's current user.
I hope that helped.

Error showing at tAccessInput component

While using tAccessInput component in my job, it showing error like,
It may not be a database that your application recognizes, or the file may be corrupt.
But, it all the connections and database/table names are valid in my job.
What can be the problem. and how can i resolve it.
Metioning the exact DBVersion is more important for tAccessInput/tAccessOutput.
Like Access 2003/Access 2007 and associated database file name.