项目作者: tobidsn

项目描述 :
a list SQL of disposable and temporary email address domains
高级语言: TSQL
项目地址: git://github.com/tobidsn/disposable-email-domains-sql.git
创建时间: 2020-05-09T22:24:38Z
项目社区:https://github.com/tobidsn/disposable-email-domains-sql

开源协议:

下载


List SQL of disposable email domains

This repo contains a list SQL of disposable and temporary email address domains often used to register dummy users in order to spam or abuse some services.

We cannot guarantee all of these can still be considered disposable but we do basic checking so chances are they were disposable at one point in time.

Example Usage

Laravel

  1. Make sure the passed email is valid. You can check that with filter_var
  1. if( filter_var($email, FILTER_VALIDATE_EMAIL))
  2. {
  3. /*
  4. * Rest of your code
  5. */
  6. }
  1. Create a model instance is using the make:model Artisan command:
  1. php artisan make:model DisposableDomain
  2. // Model created successfully.

Edit model app/DisposableDomain.php

  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class DisposableDomain extends Model
  5. {
  6. /**
  7. * The table associated with the model.
  8. *
  9. * @var string
  10. */
  11. protected $table = 'disposable_email_domains';
  12. /**
  13. * The attributes that are mass assignable.
  14. *
  15. * @var array
  16. */
  17. protected $fillable = [ 'id', 'domain'];
  18. }
  1. Use explode function and model in logic
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use Illuminate\Support\Str;
  4. use App\DisposableDomain;
  5. class AuthController extends Controller
  6. {
  7. public function filter(Request $request)
  8. {
  9. $email = $request->input('email');
  10. $domain = Str::after($email, '@');
  11. $valid = DisposableDomain::where('domain', $domain)->first();
  12. if ($valid) {
  13. // Email not valid
  14. } else {
  15. // email valid
  16. }
  17. }
  18. }
  1. Create Validation rule
  1. php artisan make:rule FakeEmail
  2. // Rule created successfully.

Final code app/Rules/FakeEmail.php

  1. <?php
  2. namespace App\Rules;
  3. use Illuminate\Contracts\Validation\Rule;
  4. use Illuminate\Support\Str;
  5. use App\DisposableDomain;
  6. class FakeEmail implements Rule
  7. {
  8. /**
  9. * Create a new rule instance.
  10. *
  11. * @return void
  12. */
  13. public function __construct()
  14. {
  15. //
  16. }
  17. /**
  18. * Determine if the validation rule passes.
  19. *
  20. * @param string $attribute
  21. * @param mixed $value
  22. * @return bool
  23. */
  24. public function passes($attribute, $value)
  25. {
  26. $email = filter_var($value, FILTER_VALIDATE_EMAIL);
  27. if ($email) {
  28. $domain = Str::after($email, '@');
  29. $exist = DisposableDomain::where('domain', $domain)->first();
  30. return $exist ? false : true;
  31. }
  32. return false;
  33. }
  34. /**
  35. * Get the validation error message.
  36. *
  37. * @return string
  38. */
  39. public function message()
  40. {
  41. return 'The :attribute must be a valid, non-disposable domain';
  42. }
  43. }

Example Project

Example Laravel 7 Project with Authentication & Validation Fake Email

Rules FakeEmail

Controller RegisterController

Model DisposableDomain