Quality tutorials & resources. No BS._

Page 3

Laravel hCaptcha Custom Validation Rule
Dan Pastori July 6th, 2020

If you are looking for an alternative to Google’s Captcha form validation, check out hCaptcha. It’s a simple, privacy focused alternative that provides an excellent screening system for bots trying to fill out your form.

Integrating with with Laravel is a breeze. Especially with Laravel’s Custom Validations that you can create, you can implement this validation on any form! Let’s get started!

0. Sign Up for an hCaptcha Account

Before we even get started, you will need to sign up for an hCaptcha account. Doing this will give you the public and secret keys needed to ensure that you can start validating hCaptchas.

1. Frontend Setup

For this tutorial, we are assuming you have hCaptcha set up on the front end, utilizing the javascript library of your choice. If you are using any of the big 3 frameworks (VueJS, React, Angular), hCaptcha’s official repository provides components that you can easily implement.

Once you have that set up, we can move to the next step.

2. Create a Custom Laravel Validation Rule

Laravel seems to have a solution for everything, and this one that I’ve been utilizing lately. It’s the ability to create a custom form validation rule. If you check out the documentation you will see there are already a variety of useful rules you can use when validating one of your forms. However, there will be a time where you will need to make your own (I’ll be sharing a few more of these custom rules later on).

All you need to do is run the following artisan command:

php artisan make:rule ValidHCaptcha

This will create a new custom validation rule class in the App\Rules directory of your app. You can of course move this to where ever you want your rules to be stored, just make sure you update the namespace correctly.

3. Breaking Down the Custom Rule

Let’s take a look at the file that was just created:

<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class ValidHCaptcha implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        //
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The validation error message.';
    }
}

The first method is the passes() method which accepts attribute and value as the parameters. The value is what we are most interested in because that’s what we will be validating. This method is the heart of what we will be implementing.

The second method, message() is the customizable error string that gets sent back to the user when the validation fails. Super handy for proper UX and telling the user exactly what went wrong when their form doesn’t validate correctly.

Okay, time to implement the hCaptcha validation.

Keep Reading →
Generating WireGuard QR codes for fast mobile deployments Part 5 of 7 in Gain flexibility & increase privacy with WireGuard VPN
Jay Rogers May 26th, 2020

If you have been following along on my Gain Flexibility & Increase Privacy with WireGuard VPN “mini-course”, you’ll notice that there are a few areas that we need apply configurations in order for our devices to get connected.

Typing all of this in manually on mobile can be a massive pain, especially if you are supporting a remote device for a user.

QR Codes to the rescue!

We can use QR codes to send VPN configuration files out. This is brilliant engineering on WireGuard’s part.

Prerequisites

Installing the package is easy. Run this command on your SERVER:

sudo apt install qrencode
Keep Reading →
How to configure a WireGuard macOS client Part 4 of 7 in Gain flexibility & increase privacy with WireGuard VPN
Jay Rogers May 26th, 2020

I am continuing my “mini-course” on Gain Flexibility & Increase Privacy with WireGuard VPN. If you haven’t seen that, that link is a great place to start. What you’ll achieve We will be connecting our macOS client to send traffic through our Ubuntu 20.04 WireGuard VPN server This is what it looks like: Prerequisites You […]

Keep Reading →