Skip to content

Instantly share code, notes, and snippets.

View thibaut-decherit's full-sized avatar

Thibaut Decherit thibaut-decherit

View GitHub Profile
@thibaut-decherit
thibaut-decherit / Symfony - Password Strength Meter (zxcvbn-HIBP powered).md
Last active August 23, 2023 16:23
Symfony - Password Strength Meter (zxcvbn-HIBP powered)

Symfony - Password Strength Meter (zxcvbn-HIBP powered)

The following code will create and update on user input a password strength meter relying on data provided by the zxcvbn estimator from Dropbox and the HaveIBeenPwned API (if reachable).

Dependencies

  • crypto-js (or any other JS library providing SHA-1 hashing, as it is required for HIBP API consuming)
  • zxcvbn
  • babel-polyfill (required to use async/await)
@thibaut-decherit
thibaut-decherit / Symfony - NPM, Webpack Encore and SASS Install (for Bootstrap 4).md
Last active August 23, 2023 16:23
Symfony - NPM, Webpack Encore and SASS Install (for Bootstrap 4)

Symfony - NPM, Webpack Encore and SASS Install (for Bootstrap 4)

If new computer start with these two:

$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash

$ sudo apt-get install -y nodejs

Then:

See:

@thibaut-decherit
thibaut-decherit / form-button.md
Last active May 11, 2024 10:15
Symfony Form Button

Form Button

Useful to send data to the server without relying on the user clicking on a link, which would send a GET request, which should not be used for destructive operations (operations with database writing).

For reference, see https://softwareengineering.stackexchange.com/questions/188860/why-shouldnt-a-get-request-change-data-on-the-server and https://stackoverflow.com/questions/46585/when-do-you-use-post-and-when-do-you-use-get

You could use it for a like button, a confirm button, a delete button...

Button with data passed

You need to activate an account. You send a link containing an activation token to the user. You could stop there and just activate the account once a GET request is sent to this url.

@thibaut-decherit
thibaut-decherit / symfony-logout-csrf-protection.md
Last active October 9, 2024 19:33
Symfony - Logout with CSRF protection

URL version (GET)

config/packages/security.yaml

security:
  firewalls:
    main:
      logout:
        path: logout
        csrf_parameter: token
 csrf_token_generator: security.csrf.token_manager
@thibaut-decherit
thibaut-decherit / Symfony - MailerService.md
Last active August 23, 2023 16:22
Symfony - MailerService

Symfony - MailerService

Dependencies:

  • Mailer events (Symfony)

app/config/services.yml

parameters:
  app.website_name: '%env(WEBSITE_NAME)%'
  app.website_url: '%env(WEBSITE_URL)%'
@thibaut-decherit
thibaut-decherit / Symfony - UniqueRandomDataGeneratorService.md
Last active June 25, 2020 14:42
Symfony - UniqueRandomDataGeneratorService

UniqueRandomDataGeneratorService

src/Service/UniqueRandomDataGeneratorService.php

<?php

namespace App\Service;

use App\Helper\RandomDataGeneratorHelper;
use Doctrine\ORM\EntityManagerInterface;
@thibaut-decherit
thibaut-decherit / Symfony - StringHelper.md
Last active August 23, 2023 16:16
Symfony - StringHelper.md

Symfony - StringHelper

src/Helper/StringHelper.php

<?php

namespace App\Helper;

/**
 * Class StringHelper
@thibaut-decherit
thibaut-decherit / Symfony - FilesystemHelper.md
Last active August 23, 2023 16:15
Symfony - FilesystemHelper.md

Symfony - FilesystemHelper

src/Helper/FilesystemHelper.php

<?php

namespace App\Helper;

use Exception;
use InvalidArgumentException;
@thibaut-decherit
thibaut-decherit / PHP - RandomDataGeneratorHelper.md
Last active August 23, 2023 16:14
PHP - RandomDataGeneratorHelper

PHP - RandomDataGeneratorHelper

src/Helper/RandomDataGeneratorHelper.php

<?php

namespace App\Helper;

use Exception;
use RuntimeException;
@thibaut-decherit
thibaut-decherit / Symfony - Increment Database Field Properly.md
Last active August 23, 2023 16:12
Symfony Increment Database Field Properly