Oracle "ORA-01017: invalid username/password; logon denied": the real causes
Fix Oracle ORA-01017 "invalid username/password": case-sensitive passwords, the wrong service or PDB, expired and locked accounts, old clients, and getting in as SYSDBA.
by OhSudo ·
Not sure this is your cause?Find it step by step: Can't connect to the database →
ORA-01017: invalid username/password; logon deniedOracle 23 words it differently:
ORA-01017: invalid credential or not authorized; logon deniedYou’ve reached the database, as the listener and the network both work. Oracle says the name and password don’t match, and for security, it won’t say which part is wrong. Before you assume a mistyped password, check the less obvious reasons here, since you may be right about the password, and on the wrong database.
TL;DR
sqlplus / as sysdba1. Is it the right database?
On Oracle 12c and later, one server holds several pluggable databases (PDBs), in one container. A user created in ORCLPDB1 doesn’t exist in the root, or in another PDB, and that gives you this error. Look at where you’re connecting:
sqlplus app@//10.0.0.5:1521/ORCLPDB1The part after the port is the service. Compare it with what exists:
Then find the user in all of them:
The common mistake: connecting to the default service, such as FREE or ORCLCDB, which is the root, when your user lives in a PDB.
2. Case and special characters
Since 11g, passwords are case-sensitive. An upgrade or a change in a client may then break a password that used to work.
Then there are the characters. A password containing @, / or $ gets misread on the command line, so quote it, and quote it for the shell too:
sqlplus 'app/"pass@word"@//10.0.0.5:1521/ORCLPDB1'An easier way is to leave it out, and let SQL*Plus ask:
sqlplus app@//10.0.0.5:1521/ORCLPDB1An @ in a password is a typical cause, since Oracle then reads what’s after it as the database. The Password Generator has a shell-safe option for this reason.
User names are stored in uppercase unless they were created in quotes. A user created as "app" must log in as "app", in quotes.
3. Locked or expired accounts
These usually have their own messages: ORA-28000: The account is locked, and ORA-28001: the password has expired. But check as an admin, as a brute-force lock or a default profile often turns out to be the reason:
SELECT username, account_status, lock_date, expiry_date, profileFROM dba_users WHERE username = 'APP';Fix it:
Who’s locking it? An application or a scheduled job with an old password can keep failing, and lock the account again. See who’s trying:
SELECT os_username, userhost, timestamp, returncodeFROM dba_audit_sessionWHERE username = 'APP' AND returncode = 1017ORDER BY timestamp DESC FETCH FIRST 10 ROWS ONLY;That view depends on your audit settings, and on newer systems, unified_audit_trail has this.
4. An old client
Old clients can’t use the newer password hashes, and they may report this same error, or ORA-28040: No matching authentication protocol. Update the client, as Oracle’s Instant Client is a free download. To see what versions a user’s password supports:
Lowering SQLNET.ALLOWED_LOGON_VERSION_SERVER in sqlnet.ora gets you past it in an emergency, at the cost of weaker password hashing. Then the user’s password must be set again for it to apply. It’s better as a short-term step while you upgrade.
5. Getting in as an admin
On the server, as the oracle operating system user, you don’t need a password. The system’s group membership does the job:
sqlplus / as sysdbaIf that says ORA-01017 too, then your system user isn’t in the dba group, or ORACLE_SID is wrong. Check both with id and echo $ORACLE_SID. SYS over the network uses a separate password file, which orapwd manages.
In Docker, with gvenzl/oracle-free, the password comes from ORACLE_PASSWORD, and it only applies on the first start, on an empty volume. To change it later:
docker exec ora resetPassword new-password-here6. A wallet or external sign-in
sqlplus /@MYDB uses a wallet, and a stale one gives this error. Run mkstore -wrl <wallet> -listCredential, and check that the entry matches. For a user set up as IDENTIFIED EXTERNALLY, sign-in comes from the system, or Kerberos or LDAP, rather than a database password.
Warning
Don’t set FAILED_LOGIN_ATTEMPTS UNLIMITED to stop an account locking. Find out what keeps failing, and fix it there, or anyone can then guess passwords all day. Also keep passwords off the command line where you can: they show up in the process list and your shell history.
Shell, we have a problem!
Similar, but different: ORA-12154 means the alias isn’t found. ORA-12541 means nothing’s listening. ORA-12514 means the service isn’t known to the listener. ORA-01045: user lacks CREATE SESSION privilege means the password’s right, and the user can’t log in, so GRANT CREATE SESSION. Once in, a missing table is ORA-00942.
Found this useful? Share it.
Found a mistake? Let us know at contact@ohsudo.com.