On this page
Represents a pair of user name and password, with a password stored in a more secure way than a usual
System.String.
Syntax
|
|---|
'Declaration
Public NotInheritable Class OracleCredential |
|
|---|
public sealed class OracleCredential |
Example
An example of a console application, connecting to Oracle using the OracleCredential class to connect to Oracle.
|
|---|
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Security;
using Devart.Data.Oracle;
class Program {
static void Main(string[] args) {
{
Console.Write("Enter user name: ");
String userName = Console.ReadLine();
// Instantiate the secure string.
SecureString securePwd = new SecureString();
ConsoleKeyInfo key;
Console.Write("Enter password: ");
do {
key = Console.ReadKey(true);
// Ignore any key out of range.
if (((int) key.Key) >= 65 && ((int) key.Key <= 90)) {
// Append the character to the password.
securePwd.AppendChar(key.KeyChar);
Console.Write("*");
}
// Exit if Enter key is pressed.
} while (key.Key != ConsoleKey.Enter);
Console.WriteLine();
try {
OracleConnection connection = new OracleConnection("Server = Ora;");
connection.Credential = new OracleCredential(userName,securePwd);
connection.Open();
// use connection...
}
catch (Exception e) {
Console.WriteLine(e.Message);
}
finally {
securePwd.Dispose();
}
}
} |
|
|---|
Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Security
Imports Devart.Data.Oracle
Class Program
Private Shared Sub Main(ByVal args As String())
If True Then
Console.Write("Enter user name: ")
Dim userName As String = Console.ReadLine()
' Instantiate the secure string.
Dim securePwd As SecureString = New SecureString()
Dim key As ConsoleKeyInfo
Console.Write("Enter password: ")
Do
key = Console.ReadKey(True)
' Ignore any key out of range
If (CInt(key.Key)) >= 65 AndAlso (CInt(key.Key) <= 90) Then
' Append the character to the password.
securePwd.AppendChar(key.KeyChar)
Console.Write("*")
End If
' Exit if Enter key is pressed.
Loop While key.Key <> ConsoleKey.Enter
Console.WriteLine()
Try
Dim connection As OracleConnection = New OracleConnection("Server = Ora;")
connection.Credential = New OracleCredential(userName, securePwd)
connection.Open()
' use connection...
Catch e As Exception
Console.WriteLine(e.Message)
Finally
securePwd.Dispose()
End Try
End If
End Sub
End Class |
Inheritance Hierarchy
System.Object
Devart.Data.Oracle.OracleCredential
See Also