Question: I have a function here that loops through an array of image files, reads the file, and uploads it to aws s3 one file at a time. 

Im trying to figure out how to track when the loop is completed and then set a useState variable to true so i can conditionally render certain elements. 

I was thinking of creating a counter and when the counter is equal to the array length, call the useState, but I wasn't sure on whats the best way to go about this. 

Any direction on this is greatly appreciated.

```
  async function handleSubmit(event) {
         event.preventDefault();

      const filesAsArray = [...fileToUpload.current.files];

        for (let i = 0; i < filesAsArray.length; i++) {                       

      const content = await readContent(filesAsArray[i]);
                      await uploadFile(content);

        }

    }

```

Answer: 
Since I don't exactly know how are you creating the new user, my guess is you are doing something like,

```
user = CustomUser.objects.create(username="boohoo", email="boo@hoo.com", password="boohoopass")

```

This user object will store the password as plain text. Django doesn't automatically converts the text to hashed value instead if you dig deeper you'll find a method called `make_password` or there's a method in `AbstractUser`, `set_password` which basically converts the string to hash value. So when you create a user, use either of these methods.

```
user = CustomUser.objects.create(username="boohoo", email="boo@hoo.com")

user.passowrd = make_password("boohoopass")

# or 

user.set_password("boohoopass")

```

Even better approach is to use the method in the `UserManager`, `create_user`, which automatically does this for you.

```
user = CustomUser.objects.create_user(username="boohoo", email="boo@hoo.com", password="boohoopass")

```

**UPDATED**
In your case your admin class must also inherit from `UserAdmin` from django. Because User admin also calls the specific functions to make such things like password hash keys.

```
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as OrigUserAdmin

@admin.register(CustomUser)
class CustomUserAdmin(OrigUserAdmin):
    list_display = (
        'id', 'first_name', 'last_name', 'username', 'email', 'is_active'
    )

```
You can use a save method for encrypting the password for the custom user model.
Use the below code for the AbstractUser method for creating encrypted password:

```
class CustomModel(AbstractUser):
    .......

    def save(self):
        user = super(CustomModel, self)
        user.set_password(self.password)
        user.save()
        return user

```