<commit_before>Hangfire.Dashboard.Authorization
================================

Some authorization filters for Hangfire's Dashboard.

Installation
-------------

This library is available as a NuGet Package:

```
Install-Package Hangfire.Dashboard.Authorization
```

Usage
------

## OWIN-based authentication

```csharp
using Hangfire.Dashboard;

public void Configure(IAppBuilder app)
{
    app.UseHangfire(config => 
    {
        config.UseAuthorizationFilters(
            new AuthorizationFilter { Users = "admin, superuser", Roles = "advanced" },
            new ClaimsBasedAuthorizationFilter("name", "value"));
    });
}
```

## Basic authentication

 *Note:* If you are using basic authentication together with OWIN security, configure Hangfire *BEFORE* OWIN security configuration.

    Please, keep in mind, if you have no SSL-based instance for your
    web application you have to disable `SslRedirect` and `RequireSsl`
    options (it's enabled by default for security reasons).
    Otherwise you will have dead redirect.

```csharp
using Hangfire.Dashboard;

public void Configure(IAppBuilder app)
{
    app.UseHangfire(config => 
    {
        config.UseAuthorizationFilters(
                new BasicAuthAuthorizationFilter(
                        new BasicAuthAuthorizationFilterOptions
                        {
                            // Require secure connection for dashboard
                            RequireSsl = true,

                            // Case sensitive login checking
                            LoginCaseSensitive = true,

                            // Users
                            Users = new[]
                            {
                                new BasicAuthAuthorizationUser
                                {
                                    Login = "Administrator-1",

                                    // Password as plain text
                                    PasswordClear = "<PASSWORD>"
                                },

                                new BasicAuthAuthorizationUser
                                {
                                    Login = "Administrator-2",

                                    // Password as SHA1 hash
                                    Password = Password = new byte[]{0xa9, 0x4a, 0x8f, 0xe5, 0xcc, 0xb1, 0x9b, 0xa6, 0x1c, 0x4c, 0x08, 0x73, 0xd3, 0x91, 0xe9, 0x87, 0x98, 0x2f, 0xbb, 0xd3}
                                }
                            }
                        }));
    });
}
```

### How to generate password hash

Just run this code:

```csharp
string password = "<<PASSWORD>>";
using (var cryptoProvider = System.Security.Cryptography.SHA1.Create())
{
    byte[] passwordHash = cryptoProvider.ComputeHash(Encoding.UTF8.GetBytes(password));<commit_msg>Readme formatting<commit_after>Hangfire.Dashboard.Authorization
================================

Some authorization filters for Hangfire's Dashboard.

Installation
-------------

This library is available as a NuGet Package:

```
Install-Package Hangfire.Dashboard.Authorization
```

Usage
------

## OWIN-based authentication

```csharp
using Hangfire.Dashboard;

public void Configure(IAppBuilder app)
{
    app.UseHangfire(config => 
    {
        config.UseAuthorizationFilters(
            new AuthorizationFilter { Users = "admin, superuser", Roles = "advanced" },
            new ClaimsBasedAuthorizationFilter("name", "value"));
    });
}
```

## Basic authentication

 *Note:* If you are using basic authentication together with OWIN security, configure Hangfire *BEFORE* OWIN security configuration.

    Please, keep in mind, if you have no SSL-based instance for your
    web application you have to disable `SslRedirect` and `RequireSsl`
    options (it's enabled by default for security reasons).
    Otherwise you will have dead redirect.

```csharp
using Hangfire.Dashboard;

public void Configure(IAppBuilder app)
{
    app.UseHangfire(config => 
    {
        config.UseAuthorizationFilters(
                new BasicAuthAuthorizationFilter(
                        new BasicAuthAuthorizationFilterOptions
                        {
                            // Require secure connection for dashboard
                            RequireSsl = true,

                            // Case sensitive login checking
                            LoginCaseSensitive = true,

                            // Users
                            Users = new[]
                            {
                                new BasicAuthAuthorizationUser
                                {
                                    Login = "Administrator-1",

                                    // Password as plain text
                                    PasswordClear = "<PASSWORD>"
                                },

                                new BasicAuthAuthorizationUser
                                {
                                    Login = "Administrator-2",

                                    // Password as SHA1 hash
                                    Password = Password = new byte[]{<PASSWORD>,
                                    0x4a, 0x8f, 0xe5, 0xcc, 0xb1, 0x9b,
                                    0xa6, 0x1c, 0x4c, 0x08, 0x73, 0xd3,
                                    0x91, 0xe9, 0x87, 0x98, 0x2f, 0xbb,
                                    0xd3}
                                }
                            }
                        }));
    });
}
```

### How to generate password hash

Just run this code:

```csharp
string password = "<<PASSWORD>>";
using (var cryptoProvider = System.Security.Cryptography.SHA1.Create())
{
    byte[] passwordHash = cryptoProvider.ComputeHash(Encoding.UTF8.GetBytes(password));
{'fraction_non_alphanumeric': 0.09154194222067526, 'fraction_numerical': 0.016359206404455272, 'mean_word_length': 1.4187710437710437, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2575933', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1332, 'n_words': 368}