You can try resetting the ambari 'admin' user's password to default 'admin' by running the following queries in the Ambari DB.
Then you should be able to login to Ambari UI as user: "admin" and password: "admin". Then you can change the password to your desired one.
1). Stop Ambari Server
# ambari-server stop
2). Take a Backup of Ambari DB (just for a safe copy)
3). Login to your Database like using psql/mysql/sqlplus utility and connect to Ambari DB then run any of the below quwery based on your Ambari Version.
If you are using Ambari 2.6 Or previous Ambari versions then you can run the following SQL Query in your Ambari DB
UPDATE users SET user_password='538916f8943ec225d97a9a86a2c6ec0818c1cd400e09e03b660fdaaec4af29ddbb6f2b1033b81b00' WHERE user_name='admin'
For Ambari 2.7.x you can run the following query in Ambari DB
UPDATE user_authentication SET authentication_key='538916f8943ec225d97a9a86a2c6ec0818c1cd400e09e03b660fdaaec4af29ddbb6f2b1033b81b00' WHERE user_id IN (SELECT user_id FROM users WHERE user_name='admin');
4). Restart Ambari Server and then login to ambari UI with admin/admin credential.
# ambari-server start
Using above approach you can change any users password to 'admin' and then later from ambari UI the password can be changed.