NETTİM
← Kod Sonuçlarına Dön
PHP MariaDB SQL sorguları Sınıflar Fonksiyonlar Kimlik doğrulama Oturum yönetimi Kullanıcı yönetimi Güvenlik işlemleri API örnekleri Lisans: Belirtilmemis

PHP — AuthController.php

PHP MariaDB entegrasyonlu — SQL sorguları, Sınıflar, Fonksiyonlar. Sınıflar: AuthController. Fonksiyonlar: register, login. SQL sorgusu içerir.
Sınırlı Önizleme Politikası: Bu kodun açık kaynak lisansı doğrulanamadığı için telif kuralları gereği yalnızca kısa önizlemesi gösterilmektedir. Tam kod için orijinal kaynağa gidin ↗.
app/controllers/AuthController.php • PHP
<?php
declare(strict_types=1);

namespace App\Controllers;

use PDO;
use PDOException;

final class AuthController
{
    /** @return array{errors: list<string>, name: string, email: string} */
    public static function register(PDO $pdo, array $input): array
    {
        $name = trim(is_string($input['name'] ?? null) ? $input['name'] : '');
        $email = strtolower(trim(is_string($input['email'] ?? null) ? $input['email'] : ''));
        $password = is_string($input['password'] ?? null) ? $input['password'] : '';
        $confirmation = is_string($input['password_confirmation'] ?? null)
            ? $input['password_confirmation']
            : '';
        $errors = [];

        $nameLength = preg_match_all('/./us', $name);
        if ($name === '' || $nameLength === false || $nameLength > 120) {
            $errors[] = 'Enter your name using no more than 120 characters.';
        }

        if ($email === '' || strlen($email) > 254 || filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
            $errors[] = 'Enter a valid email address (up to 254 characters).';
        }

        $passwordLength = preg_match_all('/./us', $password);
        if ($passwordLength === false || $passwordLength < 12 || strlen($password) > 72) {
            $errors[] = 'Use a password with at least 12 characters and no more than 72 bytes.';
        }

        if ($password !== $confirmation) {

Tespit Edilen SQL Sorguları

with at least 12 characters and no more than 72 bytes.'
SELECT id FROM users WHERE email = :email LIMIT 1')
with that email address already exists.'],
INSERT INTO users (name, email, password_hash) VALUES (:name, :email, :password_hash)'
with that email address already exists.'],
SELECT id, name, password_hash FROM users WHERE email = :email LIMIT 1'

Benzer Kod Örnekleri

PHP — HelloWorldTest.php
PHP • SQL sorguları
PHP — HelloWorld.php
PHP • SQL sorguları
PHP: Constants - Manual
PHP • SQL sorguları
PHP — edit.php
PHP • SQL sorguları