WordPress login security

Disable login with email

Update your functions.php with the following line:

remove_filter( ‘authenticate’, ‘wp_authenticate_email_password’, 20 );

Disable username discover

Hackers can search usernames by querying the author link: http://www.yoursite.com/?author=1 . You can add the following code to functions.php to redirect those urls to the homepage.

function redirect_to_home_if_author_parameter() {function
redirect_to_home_if_author_parameter() {
$is_author_set = get_query_var( ‘author’, ” );
if ( $is_author_set != ” && !is_admin()) {
wp_redirect( home_url(), 301 );
exit;
}
}
add_action( ‘template_redirect’, ‘redirect_to_home_if_author_parameter’ );

Limit login attempts

Add a plugin to limit your login attempts : https://nl-be.wordpress.org/plugins/search/login+attempts/
Use a plugin that is used a lot and is frequently updated.

Use password-like usernames

Your username should be as hard to find as your password, longer is better.

blueimp’s jQuery file uploader server side resizing

For one of my projects I’m using blueimp’s jQuery file uploader for uploading an image. The images do not need to be of high resolution but I do want to store them on the same webserver as the website. This is why I want to control the space they take on the server.

First I looked into the Client side Image Resizing feature but apparently it doesn’t work on all browsers. So I started to investigate server side resizing. Luckily the php UploadHandler can do that by just setting some options. I didn’t found any documentation about it so I’m writing it here for future reference.

Open up UploadHandler.php

Scroll down to the option ‘image_versions’

It should contain the arrays:

” => array(
‘auto_orient’ => true
),
‘thumbnail’ => array(
  ‘max_width’ => 80,
  ‘max_height’ => 80
)
The first array are the options for the original images and the second array are the options for the thumbnails. As you can see the thumbnails contain a max_width and a max_height which determine the resolution of the thumbnail.
Add the max_width and the max_height properties to the first array to enable the resizing functionality to the original images.
” => array(
  ‘auto_orient’ => true,
  ‘max_width’ => 1000,
  ‘max_height’ => 1000
),
 And that’s how you enable server side resizing.

Accessing Angular form state

Sometimes you want to access the state of an Angular form. For example a form could be invalid and you want to know why. Without digging to deep an Angular form has some validation state defined on the scope of the form:

$pristine: It will be TRUE, if the user has not interacted with the form yet
$dirty: It will be TRUE, if the user has already interacted with the form.
$valid: It will be TRUE, if all containing form and controls are valid
$invalid: It will be TRUE, if at least one containing form and control is invalid.
$error: Is an object hash, containing references to all invalid controls or forms,

Taken from: http://www.ng-vinod.com

Open up the form and launch your console.

You can now pick an element in the form, for example the confirm button:

var confirmButton = angular.element(‘.btn-primary’);

Then you can access the scope:

var confirmButtonScope = confirmButton.scope();

The scope contains the formState:

var formState = confirmButtonScope.nameOfMyForm;

And this has all the validation states: for example show all invalid fields

formState.$error;

This way you can easily debug your form without any fancy debugging tools.

Using this logic I could create an oneliner for easy debugging my forms:

angular.element(‘querySelectorToYourElement’).scope().nameOfYourForm.$error

TeamCity nuget restore “Cannot find file”

When restoring nuget packages on a build within TeamCity I got the following error messages.

C:\Program Files\dotnet\sdk\2.0.0\NuGet.targets(102,5): error : Could not find file ‘C:\Windows\system32\config\systemprofile\.nuget\packages\runtime.win7-x64.runtime.native.system.data.sqlclient.sni\4.0.1\runtime.win7-x64.runtime.native.system.data.sqlclient.sni.nuspec’.

Appearantly Nuget is trying to find nuget packages on within the systemprofile, which does not exist.

Just run the agents under a local account and the build should work.

Be sure to make the local account owner of the build agent’s directory

Error: 2002: Can’t connect to local MySQL server through socket trying to connect

Last night I faced an issue on one of my servers that I could not connect to mysql This was on a amazon ec2 instance.

Error: 2002: Can’t connect to local MySQL server through socket trying to connect ‘/var/lib/mysql/mysql.sock’ (2) when

It was trying to find ‘/var/lib/mysql/mysql.sock’ but for some reason it was gone.

Restarting mysql did not fix the issue.

I had to run:

cd /etc/init.d
sudo mysqld_safe

That would recreate the socket file and fixed my issue.