---
title: Log in with a username and password
summary: Log in with an account's credentials for development and testing, and know why production code uses an API token instead.
order: 30
languages: [javascript, java, csharp, php]
terms: [auth-token, api-token]
see-also: [how-to/auth/log-in-with-an-api-token, how-to/auth/create-an-api-token, explanation/tokens-and-delegation, explanation/accounts-and-organisations]
notion: https://www.notion.so/bimbase/Username-password-cd6afc0b288c4eaba499861457cc3e85
---

# Log in with a username and password

For trying the API from a development machine with the account you also use in the UI. Every SDK supports it; production code should use an [[term:api-token|API token]] instead, which is revocable, scoped to one folder and not tied to a person's password.

## Before you start

- A BIM.works account whose e-mail address is validated. An unvalidated account cannot log in ([[error:EMAIL_ADDRESS_NOT_VALIDATED]]).
- An account **without two-factor authentication**. With it, the password step answers a `twofa` challenge that the SDKs do not complete; use an API token for such accounts.

## 1. Log in

```code-group {#login} classic
```javascript
const factory = new BimWorksClientFactory(BIM_WORKS_ADDRESS);
const client = await factory.createClientWithUsernamePassword("you@example.com", "your password");
```
```java
try (BimWorksClientFactory factory = new BimWorksClientFactory(BIM_WORKS_ADDRESS);
		BimWorksClient client = factory.createClientWithUsernamePassword("you@example.com", "your password")) {
	// use the client
}
```
```csharp
using (BimWorksClientFactory factory = new BimWorksClientFactory(new Uri(BIM_WORKS_ADDRESS)))
using (BimWorksClient client = factory.CreateClientWithUsernamePassword("you@example.com", "your password"))
{
    // use the client
}
```
```

```sdk-example
operation: LoginWithUsernamePassword
body: |
  {
    "username": "you@example.com",
    "password": "your password"
  }
```

The factory method is `createClientWithUsernamePassword` ([[page:reference/javascript]], [[page:reference/java]]) or `CreateClientWithUsernamePassword` ([[page:reference/dotnet]]); PHP calls `AuthApi::loginWithUsernamePassword` ([[page:reference/sdk/php]]). The HTTP operation is [[openapi:LoginWithUsernamePassword]]; it also returns the bearer token in the `Authorization` response header:

```try-it
operation: LoginWithUsernamePassword
method: POST
path: /openapi/auth/LoginWithUsernamePassword
body: |
  {
    "username": "you@example.com",
    "password": "your password",
    "response_format": "base64"
  }
```

## 2. Know what you got

- The [[term:auth-token|auth token]] lives **7 days** (`auth.username_password_token_validity`); the UI's "remember me" variant lives 90 days.
- The root node is the account's own folder; organisation folders the account can see are listed under it.
- The scopes are the account's, so the token can do everything you can do in the UI, including creating API tokens and delegated tokens.
- A wrong password, an unknown address or a deleted account all answer [[error:AuthenticationError.INVALID_LOGIN]] (a deleted account [[error:ACCOUNT_DELETED]]), and repeated failures are throttled per account and per address.

```warning
The username is an e-mail address and the password is the one you type in the UI. Do not put them in a configuration file that ships with an application; create an API token on the folder the application needs and give it that ([[page:how-to/auth/create-an-api-token]]).
```

## Check

```code-group {#check} classic
```javascript
const root = await client.fs.getNodeByPath("/");
console.log(root.name);   // your account's folder
```
```java
System.out.println(client.fs.getRootNode().getName());
```
```csharp
Console.WriteLine(client.Fs.GetRootNode().Name);
```
```

```sdk-example
operation: GetNode
body: |
  {
    "path": "/"
  }
```

The root node's name is your account's folder name. The calls: `getNodeByPath`/`getRootNode` on [[js:@bimworks/jssdk/Fs|Fs]], [[java:nl.bimbase.bimworks.client.apis.FileSystemApi|FileSystemApi]] and [[dotnet:BIM.works_SDK.Fs|Fs]], `FsApi::getNode` in [[page:reference/sdk/php]], [[openapi:GetNode]] over HTTP.
