> ## Documentation Index
> Fetch the complete documentation index at: https://docs.4r.sa/llms.txt
> Use this file to discover all available pages before exploring further.

# Password Protection

> Secure your shortened URLs with password protection

## Overview

Password protection adds an extra layer of security to your shortened URLs. Users must enter the correct password before being redirected to the destination.

## Use Cases

<CardGroup cols={2}>
  <Card title="Private Content" icon="lock">
    Share confidential documents or internal resources
  </Card>

  <Card title="Exclusive Access" icon="star">
    Provide VIP or early access to select users
  </Card>

  <Card title="Event Registration" icon="ticket">
    Control access to event materials
  </Card>

  <Card title="Beta Testing" icon="flask">
    Limit access to beta features or products
  </Card>
</CardGroup>

## Creating Password-Protected URLs

```javascript theme={null}
const response = await axios.post('https://snip.sa/api/urls', {
  originalUrl: 'https://example.com/private-content',
  customCode: 'private-doc',
  title: 'Confidential Document',
  password: 'SecurePass123!',
  description: 'Internal use only'
}, {
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'your_api_key_here'
  }
});
```

## Password Requirements

<Note>
  Passwords must meet these requirements:

  * Minimum 8 characters
  * At least one uppercase letter
  * At least one lowercase letter
  * At least one number
  * Special characters recommended
</Note>

## User Experience

When users visit a password-protected URL:

1. They see a password prompt page
2. Enter the password
3. If correct, they're redirected to the destination
4. If incorrect, they see an error message

## Updating Password

Change the password for an existing URL:

```javascript theme={null}
const response = await axios.put(
  'https://snip.sa/api/urls/507f1f77bcf86cd799439011',
  {
    password: 'NewSecurePass456!'
  },
  {
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': 'your_api_key_here'
    }
  }
);
```

## Removing Password Protection

Set password to `null` to remove protection:

```javascript theme={null}
const response = await axios.put(
  'https://snip.sa/api/urls/507f1f77bcf86cd799439011',
  {
    password: null
  },
  {
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': 'your_api_key_here'
    }
  }
);
```

## Combining with Other Features

### Password + Expiration

```javascript theme={null}
{
  originalUrl: 'https://example.com/limited-offer',
  password: 'LimitedOffer2024',
  expiresAt: '2024-12-31T23:59:59Z',
  title: 'Limited Time Offer'
}
```

### Password + Click Limit

```javascript theme={null}
{
  originalUrl: 'https://example.com/exclusive',
  password: 'VIP2024',
  restrictions: {
    maxClicks: 100
  },
  title: 'VIP Access - Limited to 100 users'
}
```

### Password + Geographic Restrictions

```javascript theme={null}
{
  originalUrl: 'https://example.com/regional-content',
  password: 'Regional2024',
  restrictions: {
    allowedCountries: ['US', 'CA', 'GB']
  },
  title: 'Regional Content'
}
```

## Best Practices

<AccordionGroup>
  <Accordion icon="shield" title="Use Strong Passwords">
    * Avoid common words or patterns
    * Use a mix of characters
    * Consider using a password generator
    * Don't reuse passwords across URLs
  </Accordion>

  <Accordion icon="share" title="Secure Password Sharing">
    * Share passwords through secure channels
    * Don't include password in the same message as the link
    * Use encrypted messaging apps
    * Consider time-limited passwords
  </Accordion>

  <Accordion icon="clock" title="Rotate Passwords">
    * Change passwords periodically
    * Update passwords if compromised
    * Use expiration dates for time-sensitive content
  </Accordion>

  <Accordion icon="chart-line" title="Monitor Access">
    * Track click analytics
    * Monitor for unusual access patterns
    * Set up alerts for high traffic
  </Accordion>
</AccordionGroup>

## Analytics for Protected URLs

Password-protected URLs still track analytics:

```javascript theme={null}
const analytics = await axios.get(
  'https://snip.sa/api/analytics/507f1f77bcf86cd799439011',
  {
    headers: { 'X-API-Key': 'your_api_key_here' }
  }
);

// Track successful password entries
console.log('Successful Access:', analytics.data.data.totalClicks);
```

<Tip>
  Failed password attempts are not counted in click analytics, only successful accesses.
</Tip>

## Example: Event Access System

```javascript theme={null}
class EventAccessManager {
  constructor(apiKey) {
    this.apiKey = apiKey;
  }

  async createEventAccess(eventName, eventUrl, attendeePassword) {
    const response = await axios.post('https://snip.sa/api/urls', {
      originalUrl: eventUrl,
      customCode: eventName.toLowerCase().replace(/\s+/g, '-'),
      title: `${eventName} - Attendee Access`,
      password: attendeePassword,
      expiresAt: this.getEventEndDate(),
      restrictions: {
        maxClicks: 500  // Max attendees
      },
      tags: ['event', 'private']
    }, {
      headers: {
        'Content-Type': 'application/json',
        'X-API-Key': this.apiKey
      }
    });

    return response.data;
  }

  getEventEndDate() {
    const date = new Date();
    date.setDate(date.getDate() + 7);  // Event lasts 7 days
    return date.toISOString();
  }
}

// Usage
const manager = new EventAccessManager('your_api_key');
const eventAccess = await manager.createEventAccess(
  'Annual Conference 2024',
  'https://example.com/conference-materials',
  'Conference2024!'
);
```
