Sunday, January 21, 2024

Replace all occurrences of the old class with the new class


$('.old-class').removeClass('old-class').addClass('new-class');

Sunday, January 14, 2024

THE PERSON YOU WILL BE IN 5 YEARS DEPENDS LARGELY ON

1. The books you read

2. The people you spend time with

3. The habits you adopt

4. The food you eat

5. The conversations you engage in 

Sunday, January 7, 2024

How do I log in a user with a master password in Laravel

 In Laravel, logging in a user with a master password is a feature that isn't provided out-of-the-box, but it can be implemented with some custom code. A master password is a single password that can be used to log in as any user, which can be useful for administrators or developers needing access to multiple accounts. However, this approach should be used cautiously due to its security implications. Here's a general approach you can take:

Prerequisites

  • A Laravel project setup
  • Familiarity with Laravel's authentication system
  • A User model and corresponding database table

Steps to Implement a Master Password

1. Environment Configuration

Set the master password in your .env file for security.
MASTER_PASSWORD=YourMasterPasswordHere

2. User Model Modification

  • Add a method to the User model to validate the master password.
  • public function validateMasterPassword($password) { return $password === env('MASTER_PASSWORD'); }

3. Customizing the Login Controller

  • Override the credentials method in your LoginController.
protected function credentials(Request $request)
{
    $password = $request->get('password');

    // Check if the password is the master password
    if (User::first()->validateMasterPassword($password)) {
        // Use the email provided to log in
        return ['email' => $request->get('email'), 'password' => $password];
    }

    // Default behavior
    return $request->only($this->username(), 'password');
}


Security Considerations

  • Usage Logging: Always log when the master password is used, including details like who used it, when, and for which account.
  • Access Control: Restrict the use of the master password to specific IP addresses or during specific times.
  • Auditing: Regularly review the logs to detect any unauthorized or suspicious use.
  • Complexity: Ensure the master password is complex and changed regularly.
  • Encryption & Security Practices: Keep the master password encrypted and follow best security practices to prevent leaks.

Wednesday, July 12, 2023

How to align all li on one line

 HTML

<UL class="fruit-prop">
    <LI>Apple</LI>
    <LI>Orange</LI>
    <LI>Banana</LI>
    <LI>Mango</LI>
</UL>
CSS
ul.fruit-prop {
display: table; width: 100%; text-align: center; } ul.fruit-prop > li {
display: table-cell; }
SCSS
ul {
  &.fruit-prop {
display: table; width: 100%; text-align: center; > li { display: table-cell; } } }

Tuesday, July 11, 2023

Print sql query in Laravel

 Use the following code to print query in Laravel, There are following way to print query in Laravel

1.    \DB::enableQueryLog();

2.    dd(\DB::getQueryLog());

3.    User::where('user_id', $iserId)->toSql();

Wednesday, June 1, 2022

Setup a master password for your laravel application.

 Most of the time we face issue, to login other's account to help them. But we cannot ask them.

 Solution is to setup master password so that each account have 2 password.


  Follow the following steps

  Step1:-  Install composer 

                composer require imanghafoori/laravel-masterpass

   Step2:-  Then, do not forget to run:

                 php artisan vendor:publish --tag=master_password

   Step3:- Add this to your .env

                MASTER_PASSWORD=mySecretMasterPass

               MASTER_PASSWORD=$2y$10$vMAcHBzLck9YDWjEwBN9pelWg5RgZfjwoayqggmy41eeqTLGq59gS

  



Saturday, May 7, 2022

Enable query log Laravel

 Use the enableQueryLog method: Use the enableQueryLog method:

DB::connection()->enableQueryLog();



We can get an array of the executed queries by using the getQueryLog method:

$queries = DB::getQueryLog();

Wednesday, April 7, 2021

Find all IDs in a class : JQuery

 

var idArray = [];

$('.red').each(function () {
    idArray.push(this.id);
});

jQuery: sending JSON data to PHP with AJAX

 Passing JSON data with jQuery and AJAX to Node.js is relatively simple, passing JSON data with jQuery and AJAX to PHP requires a few extra steps.

Instead of trying to send JSON as is, you should only send a well-formed JSON string and let PHP to transform it into an object or an associative array (depending on how you use the json_decode() function).

Bear in mind that PHP not only requires the string to be valid JSON: your string must also be UTF-8 compliant. So with jQuery we can write:

var data = {

  test: $( "#test" ).val()

};

var options = {

  url: "test.php",

  dataType: "text",

  type: "POST",

  data: { test: JSON.stringify( data ) }, // Our valid JSON string

  success: function( data, status, xhr ) {

     //...

  },

  error: function( xhr, status, error ) {

      //...

  }

};

$.ajax( options );

And with PHP we have to take care of the string encoding before using it:

<?php

  header('Content-Type: text/plain');

  $test = utf8_encode($_POST['test']); // Don't forget the encoding

  $data = json_decode($test);

  echo $data->test;

  exit();

 ?>

Reff : https://gabrieleromanato.name/jquery-sending-json-data-to-php-with-ajax

Saturday, February 27, 2021

Tooltip For Angular

1.  Installation

    npm i ng2-tooltip-directive

2. Import Ng2Module

import { TooltipModule } from 'ng2-tooltip-directive';

  @NgModule({

imports: [ TooltipModule ]

})

3. Usage

Options can be set in the directive tag, so they have the highest priority.

<span tooltip="Tooltip" placement="top" show-delay="500">Tooltip on top</span>

may pass as an object:

<span tooltip="Tooltip" [options]="myOptions">Tooltip on left</span>

myOptions = {

'placement': 'left',

'show-delay': 500

}

Pass HTML as content:

<span tooltip="<p>Hello i'm a <strong>bold</strong> text!</p>">

  Tooltip with HTML content

</span>

<ng-template #HtmlContent>

  <p>Hello i'm a <strong>bold</strong> text!</p>

</ng-template>

 <span [tooltip]="HtmlContent" content-type="template">

  Tooltip with template content

</span>