#!/bin/bash

replacePlainPasswords() 
{
    local file="$1"

    # Only scan for placeholders that actually exist in the file
    local existing_placeholders=$(runInstallOp grep -oE 'RANDOMIZEDPASSWORD[0-9]+' "$file" 2>/dev/null | sort -u)
    
    if [[ -n "$existing_placeholders" ]]; then
        while IFS= read -r password_placeholder; do
            if [[ -n "$password_placeholder" ]]; then
                local random_password=$(generateRandomPassword)
                runInstallOp sed -i 's/'"${password_placeholder}"'/'"${random_password}"'/g' "$file"
                checkSuccess "Updated ${password_placeholder} in $(basename "$file")."
            fi
        done <<< "$existing_placeholders"
    fi
}
