Tuesday 25 August 2020

PHP Username Validation program

 

PHP Username Validation program

Creat function usernameValidation(str) take the str parameter being passed and determine if the string is a valid username according to the following rules:
  1. The username is between 4 and 25 characters.
  2. It must start with a letter.
  3. It can only contain letters, numbers, and the underscore character.
  4. It cannot end with an underscore character.
If the username is valid then your program should return the string true, otherwise return the string false

Solution:
function usernameValidation($str) {
    $return = true;
    
    ////////////////// 4 to 25 character////////////
    if ($return) {
        if (!(strlen($str) >= 4 && strlen($str) <= 25)) {
            $return = false;
        }
    }
    ////////////////// 4 to 25 character////////////
    
    ////////////////// Must start with Number ////////////
    if ($return) {
        $asciiCode = ord($str[0]);
        if (!(($asciiCode >= 97 && $asciiCode <= 122) || ($asciiCode >= 65 && $asciiCode <= 90))) {
            $return = false;
        }
    }
    ////////////////// Must start with Number ////////////
    
    ///////////// It can only contain letters, numbers, and the underscore character.///////////
    if ($return) {
        for ($i = 0; $i < strlen($str); $i++) {
            $asciiCode = ord($str[$i]);
            if (!( ($asciiCode >= 97 && $asciiCode <= 122) || ($asciiCode >= 65 && $asciiCode <= 90) || ($asciiCode >= 48 && $asciiCode <= 57) || ($asciiCode == 95))) {
                $return = false;
                break;
            }
        }
    }
    ///////////// It can only contain letters, numbers, and the underscore character.///////////
    
    ///////////It cannot end with an underscore character.///////////
    if ($return) {
        $asciiCode = ord($str[$i - 1]);
        if ($asciiCode == 95) {
            $return = false;
        }
    }
    ///////////It cannot end with an underscore character.///////////
    
    return $return ? 'true' : 'false';
}

Docker tutorial for beginners

Docker tutorial for beginners

Question: What is docker?
Docker is a container management service.
It is for mainly for developers to easily develop applications, push them into containers which then be deployed anywhere to physical server/virtual server/cloud server.


Question: Features of Docker?
  1. Docker containers are lightweight so they can be easily scalable.
  2. Deploy docker containers on any physical and virtual machines and even on the cloud.
  3. Docker has the ability to reduce the size of development by providing a smaller part of the operating system via containers



Question: What is container in docker?
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.
Applications are better shape in containers and Docker provides the isolation capabilities.


Question: What is docker image?
A Docker image is a file, comprised of multiple layers, that is used to execute code in a Docker container.
Images can exist without containers, whereas a container needs to run an image to exist.


Question: What is a docker hub repository?
Docker Hub is a hosted repository service provided by Docker for searching and sharing container images.
hosted repository can be public or private.
URL: hub.docker.com


Question: How to install docker in windows 10 Pro?
  1. Open the link : Download docker for windows
  2. Click on "Get Stable" Link
  3. Download the file
  4. Once downloaded, then simply install



Question: How to check the version of docker?
docker --version



Question: How to list the running docker containers ?
docker container ls



Question: How to list the all docker containers ?
docker container ls -a



Question: How to list the all docker images?
docker images



Question: How to pull the docker container from docker hub?
docker run --name my-mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql