# SqlMembershipProvider

[]( [Documentation](

Read and authenticate against ASP.NET Membership Microsoft SQL Server databases.

Do you have an ASP.NET app that uses the built-in Membership Provider that
stores users, passwords, roles, and profiles in a Microsoft SQL Server database?

This library lets your Elixir code talk to a Membership Provider database to lookup users, their profile information roles they belong to, and authenticate their passwords.

This library uses [Tds]( and [Ecto]( to connect to a Microsoft SQL Server database.

## Usage

First you must define an [Ecto.Repo]( to connect to the MSSQL database:

defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Ecto.Adapters.Tds

Make sure to configure your database credentials:

config :my_app, MyApp.Repo,
  database: "aspnetdb",
  hostname: "localhost",
  password: "password",
  port: 1433,
  username: "username"

Now you can query for users:

iex(1)> user = SqlMembershipProvider.User.find_by_user_name("JohnDoe")

iex(2)> membership = SqlMembershipProvider.Membership.find_by_user_id(user.user_id)

iex(3)> SqlMembershipProvider.Membership.is_password_valid?(membership, "password!")

iex(4)> profile = SqlMembershipProvider.Profile.find_by_user_id(user.user_id)

  "FirstName" => "John",
  "LastName" => "Doe",

iex(6)> roles = SqlMembershipProvider.Role.find_by_user_id(user.user_id)
    role_name: "Administrators",

## Running Tests

Clone the repo and fetch its dependencies:

$ git clone
$ cd sql_membership_provider
$ mix deps.get

[Docker Compose]( is required to run a
sample SQL Server database to run integration tests against.

$ docker-compose up
$ ./
$ mix test

## Future Work

There are tables remaining to be mapped to schemas. Functions to update data
like the password and profile properties still need to be implemented.

## Help Wanted

* Only the SHA1 password format is supported. Support should be added for [the
  remaining password formats](
* Add support for reading binary properties from profiles