# Importing users with hashed passwords into OKTA

**URL:** <https://devforum.okta.com/t/importing-users-with-hashed-passwords-into-okta/15635>\
**Category:** Questions\
**Created:** [August 23, 2021, 8:44am UTC](https://devforum.okta.com/t/importing-users-with-hashed-passwords-into-okta/15635 "2021-08-23T08:44:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![new-developer-okta](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@new-developer-okta](https://devforum.okta.com/u/new-developer-okta)\
**Post date:** [August 23, 2021, 8:44am UTC](https://devforum.okta.com/t/importing-users-with-hashed-passwords-into-okta/15635/1 "2021-08-23T08:44:59Z")

</div>

My aim is to import existing users into OKTA (and keep their passwords same as before). I am using this python code from Okta developer website to create the hashed password (see below):

import hashlib  
import base64  
import json

password = “test password”

hashed = hashlib.sha1(bytes(password, ‘utf-8’))  
result = {  
“algorithm”: “SHA-1”,  
“value”: base64.b64encode(hashed.digest()).decode(“ascii”),  
}  
print(json.dumps(result, indent=4))

After this, I am using the OKTA API call to test and create my test user but i cannot seem to login with the password set in this process.

Even with using the examples from the developer website exactly the same, I still cannot make it work. Wondering if something is wrong with the example code or am i missing something ?

Thanks so much for the help, in advance !

---

<div class="post-metadata">

**Author:** ![erik](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@erik](https://devforum.okta.com/u/erik)\
**Post date:** [August 23, 2021, 11:37am UTC](https://devforum.okta.com/t/importing-users-with-hashed-passwords-into-okta/15635/2 "2021-08-23T11:37:30Z")

</div>

Hello,  
I assume you are following this sample [https://developer.okta.com/blog/2021/03/05/ultimate-guide-to-password-hashing-in-okta#hash-only-1](https://developer.okta.com/blog/2021/03/05/ultimate-guide-to-password-hashing-in-okta#hash-only-1)?  
If so can you supply the entire API import command you use to import the user into Okta.

If I use,

```auto
curl --location --request POST 'https://{ORG}.okta.com/api/v1/users?activate=true' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: SSWS {API_TOKEN}' \
--data-raw '{
  "profile": {
    "firstName": "Hashed",
    "lastName": "Pass",
    "email": "hash@pass.com",
    "login": "hash@pass.com"
  },
  "credentials": {
    "password" : {
      "hash": {
        "algorithm": "SHA-1",
        "value": "LOsCqF9tTebCiy5Z/aiG1Sba+w0="
      }
    }
  }
}'

```

I am able to login fine using,  
user: [hash@pass.com](mailto:hash@pass.com)  
pass: ‘test password’

---

<div class="post-metadata">

**Author:** ![iksnil](https://avatars.discourse-cdn.com/v4/letter/i/f0a364/32.png) [@iksnil](https://devforum.okta.com/u/iksnil)\
**Post date:** [January 18, 2022, 4:48pm UTC](https://devforum.okta.com/t/importing-users-with-hashed-passwords-into-okta/15635/3 "2022-01-18T16:48:15Z")

</div>

I have similar issue, hope it’s fine to add it here instead of creating a new post.

My passwords are generated by PHP [crypt](https://www.php.net/manual/en/function.crypt.php) function using SHA-512 algorithm.

```auto
$salt = '$6$rounds=1000$' . 'my-salt' . '$';
$password = crypt('my-password', $salt)

```

I read [The Ultimate Guide to Password Hashing in Okta | Okta Developer](https://developer.okta.com/blog/2021/03/05/ultimate-guide-to-password-hashing-in-okta#sha-512) and [Users | Okta Developer](https://developer.okta.com/docs/reference/api/users/#hashed-password-object) , but I still cannot login to Okta using my passwords. This is my code:

```auto
return [
        'algorithm' => 'SHA-512',
        'saltOrder' => 'PREFIX',
        'salt' => base64_encode($salt),
        'value' => base64_encode($password),
    ];

```

Any help is much appreciated.

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [February 12, 2024, 6:08pm UTC](https://devforum.okta.com/t/importing-users-with-hashed-passwords-into-okta/15635/4 "2024-02-12T18:08:33Z")

</div>

Closed on February 12, 2024, 6:08pm UTC


