Saturday, 11 March 2023

How to Build an Authentication API with JWT Token in Perl

Hi, In many web applications, user authentication is a critical feature that allows users to securely log in and access their data. One common approach to implementing authentication is to use JSON Web Tokens (JWT), which are a type of token-based authentication that can be used across multiple domains and platforms.

In this tutorial, we will show you how to build an authentication API with JWT token in Perl. We will be using the Mojolicious web framework, which is a powerful and flexible framework that makes it easy to build web applications in Perl.

Read more »

Labels: , , ,

Tuesday, 7 March 2023

Perl Code for Gmail Validator



To validate a Gmail address using regular expressions in Perl, you can use the following code:


#!/usr/bin/perl

use strict;

use warnings;

sub is_valid_gmail {

    my $email = shift;

    # Regular expression pattern for Gmail address validation

    my $pattern = qr/^[a-zA-Z0-9._%+-]+@gmail\.com$/;

    if ($email =~ $pattern) {

        return 1;  # Valid Gmail address

    } else {

        return 0;  # Invalid Gmail address

    }

}

# Testing the function

my $email1 = 'example@gmail.com';

my $email2 = 'invalid_email@gmail.com';


if (is_valid_gmail($email1)) {

    print "$email1 is a valid Gmail address\n";

} else {

    print "$email1 is not a valid Gmail address\n";

}


if (is_valid_gmail($email2)) {

    print "$email2 is a valid Gmail address\n";

} else {

    print "$email2 is not a valid Gmail address\n";

}


This code defines a Perl subroutine is_valid_gmail that takes an email address as input and checks if it is a valid Gmail address. The regular expression pattern ^[a-zA-Z0-9._%+-]+@gmail\.com$ is used to match the email address against the Gmail format.

To test the function, two email addresses are provided: example@gmail.com and invalid_email@gmail.com. The function is called for each email address, and the result is printed to the console.

Please note that this code only validates the format of the email address and checks if it ends with @gmail.com. It does not verify if the email address actually exists or is currently in use.

Labels: