Skip to main content
POST
/
auth
/
check_user.php
Verify Email
curl --request POST \
  --url https://api.example.com/auth/check_user.php \
  --header 'Accept: <accept>' \
  --header 'Content-Type: <content-type>' \
  --data '
{
  "email": "<string>"
}
'
{
  "exists": true
}

Endpoint

POST /auth/check_user.php
Verify whether a user account exists for the given email address. Useful for checking if an email is already registered before attempting registration.

Headers

Content-Type
string
required
Must be application/json
Accept
string
required
Must be application/json

Request Body

email
string
required
Email address to check

Response

exists
boolean
required
true if a user with this email exists, false otherwise

Request Example

curl -X POST https://76.13.114.194/auth/check_user.php \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "email": "[email protected]"
  }'

Response Example

{
  "exists": true
}

Use Cases

Pre-Registration Validation

Check if an email is available before showing the registration form:
Future<void> validateEmail(String email) async {
  final exists = await checkEmailExists(email);
  
  if (exists) {
    showError('Este email ya está registrado. ¿Desea iniciar sesión?');
    // Show login option
  } else {
    // Proceed with registration
    navigateToRegistrationForm(email);
  }
}

Forgot Password Flow

Verify the email exists before sending a password reset:
async function initiatePasswordReset(email) {
  const exists = await checkEmailExists(email);
  
  if (!exists) {
    alert('No hay cuenta asociada con este email');
    return;
  }
  
  // Send password reset email
  await sendPasswordResetEmail(email);
}

Smart Login/Register

Determine whether to show login or registration:
Future<void> handleEmailSubmit(String email) async {
  final exists = await checkEmailExists(email);
  
  if (exists) {
    // Show password field for login
    setState(() {
      showPasswordField = true;
      isLoginMode = true;
    });
  } else {
    // Navigate to registration
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => RegisterScreen(email: email),
      ),
    );
  }
}

Error Handling

This endpoint returns {"exists": false} on any error or if the request times out. This prevents exposing information about whether emails exist in the database during error conditions.
Future<Map<String, dynamic>> checkUserExists(String email) async {
  try {
    final response = await client.post(
      Uri.parse('$_baseUrl/check_user.php'),
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
      },
      body: jsonEncode({'email': email}),
    ).timeout(AppConfig.connectionTimeout);

    if (response.statusCode == 200) {
      return jsonDecode(response.body) as Map<String, dynamic>;
    }

    return {'exists': false};
  } catch (e) {
    return {'exists': false};
  }
}

Security Considerations

This endpoint can be used to enumerate registered email addresses. In a production environment, consider:
  • Rate limiting to prevent abuse
  • CAPTCHA for repeated checks
  • Logging suspicious activity
  • Generic error messages that don’t reveal user existence

See Also

Build docs developers (and LLMs) love