Jump to content
Sign in to follow this  
support

Validate Password for Oracle Account (by Click Studios)

Recommended Posts

Script Name

Validate Password for Oracle Account

 

Description

Checks if an Oracle Database Account Password is correct

 

System Requirements

  • Installation of Oracle Data Access Components on Passwordstate web server

 

Successfully Tested Against

  • Oracle 11g 
  • Oracle 12c
  • Oracle 11g Express

 

Failed Testing Against

  • None Reported

 
PowerShell Script

<#
.SYNOPSIS
Connect to a Oracle database server and validates the password for a account.
.NOTES
Requires database connections on in-use Port to be allowed through Firewall, and Oracle Data Access Components to be installed
#>
function Validate-OraclePassword
{
	[CmdletBinding()]
	param (
		[String]$HostName,
		[String]$ServiceName,
		[String]$SQLPort,
		[String]$UserName,
		[String]$CurrentPassword
	)

	try
	{
		Add-Type -Path '[Path to ODP.NET Folder]\odp.net\managed\common\Oracle.ManagedDataAccess.dll'
		
		$SQLConnectionString = "Data Source= (DESCRIPTION =(ADDRESS =(PROTOCOL = TCP)(HOST = " + $HostName + ")(PORT = " + $SQLPORT + "))(CONNECT_DATA =(SERVICE_NAME = " + $ServiceName + ")));User Id=" + $UserName + ";Password=" + $CurrentPassword + ";"
		$SQLConnection = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($SQLConnectionString)
		$SQLConnection.Open()
		$SQLConnection.Close()
		Write-Output "Success"
	}
	catch
	{
		switch -wildcard ($error[0].Exception.ToString().ToLower())
		{
			"*Connect timeout occurred*" { Write-Output "Failed to execute script correctly against Host '$HostName' for the account '$UserName'. Please check the Oracle Host Name and connection properties are correct, and that a firewall is not blocking access."; break }
			"*logon denied*" { Write-Output "Failed to connect to the Host '$HostName' to reset the password for the account '$UserName'. UserName or Password is incorrect."; break }
			"*Unable to resolve*" { Write-Output "Failed to connect to the Host '$HostName' to validate the password for the account '$UserName'. Please check the Oracle Host Name and connection properties are correct."; break }
			"*TNS: No listener*" { Write-Output "Failed to connect to the Host '$HostName' to validate the password for the account '$UserName'. Please check the Oracle Host Name and connection properties are correct."; break }
			"*TNS:listener does not currently know*" { Write-Output "Failed to connect to the Host '$HostName' to validate the password for the account '$UserName'. Please check the Oracle Host Name and connection properties are correct."; break }
			"*Cannot find path*" { Write-Output "Failed to find the Oracle Data Access Components. Either the path specified is incorrect, or the Data Access Components are yet to be installed."; break }
			"*cannot find the file*" { Write-Output "Failed to find the Oracle Data Access Components. Either the path specified is incorrect, or the Data Access Components are yet to be installed."; break }
			#Add other wildcard matches here as required
			default { Write-Output "Failed to validate the password for the Oracle account '$UserName' on Host '$HostName'. Error = " + $error[0].Exception }
		}
	}
}

#Make a call to the Validate-OraclePassword function
Validate-OraclePassword -HostName '[HostName]' -ServiceName '[ServiceName]' -SQLPort '[DatabasePort]' -Username '[UserName]' -CurrentPassword '[CurrentPassword]'

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×