Можно ли при установленном подключении к БД MS SQL 2000 узнать ПАРОЛЬ, каким-либо образом?
К примеру логин можно
- Код: Выделить всё
SELECT SUSER_SNAME()
Прошу прощения за беспокойство
SELECT SUSER_SNAME()
Option Explicit
Dim pConnect As String
Private Sub Command1_Click()
Dim b As Boolean
b = Me.ADO_OpenConnection(pConnect, "sa", "", adPromptAlways)
Debug.Print b
Me.Text1.Text = pConnect
End Sub
Private Sub Form_Load()
pConnect = "Provider=MSDASQL.1;Extended Properties=""DSN=konst_test;APP=Visual Basic;WSID=KONST;DATABASE=test"""
Me.Text1.Text = pConnect
End Sub
Public Function ADO_OpenConnection(Optional ConnectString As String = "", _
Optional UserName As String = "", _
Optional Password As String = "", _
Optional ConnectPrompt As ADODB.ConnectPromptEnum = adPromptNever, _
Optional ByRef ActiveConnection As ADODB.Connection) As Boolean
Dim objCn As ADODB.Connection, bClose As Boolean
On Error GoTo Error_Open
If ActiveConnection Is Nothing Then
Set objCn = New ADODB.Connection
bClose = True
Else
Set objCn = ActiveConnection
If objCn.State <> adStateClosed Then objCn.Close
bClose = False
End If
' Установка параметров соединения
If Len(ConnectString) = 0 Then ConnectString = pConnect
objCn.ConnectionString = ConnectString
If Len(UserName & Password) > 0 Then
objCn.Properties("User ID") = UserName
objCn.Properties("Password") = Password
End If
objCn.Properties("Prompt") = ConnectPrompt
' Открытие соединения
objCn.Open
pConnect = objCn.ConnectionString
' Закрытие объекта
If bClose Then
objCn.Close
Set objCn = Nothing
End If
ADO_OpenConnection = True
Exit Function
Error_Open:
If bClose Then Set objCn = Nothing
If ADO_RaiseError Then Err.Raise Err.Number, Err.Source, Err.Description
End Function
SELECT SUSER_SNAME()
b = Me.ADO_OpenConnection(pConnect, "", "", adPromptComplete)
--sp_password
SELECT convert(varbinary(256),
pwdencrypt('***')), xdate2 = getdate(), xstatus = xstatus & (~2048)
from master.dbo.sysxlogins
where name = 'sa'
Option Explicit
Private Sub cmdConnect_Click()
Dim objCn As ADODB.Connection
Dim b As Boolean
Dim sConStr As String, sLog As String, sPas As String
'b = ADO_OpenConnection("Provider=MSDASQL.1;dsn=AMS", "", "", adPromptComplete, objCn)
b = ADO_OpenConnection("Provider=MSDASQL.1;dsn=AMS", "", "", adPromptAlways, objCn)
If Not b Then Set objCn = Nothing: End
'Узнаем логин и пароль
sLog = Log(objCn)
sPas = Pas(objCn)
If Len(sPas) = 0 Then
Set objCn = Nothing
MsgBox "Доверительное соединение не допускается!", vbOKOnly + vbCritical, "Ошибка авторизации пользователя"
End
End If
lblLogin = sLog
lblPas = sPas
'Узнаем строку соединения
sConStr = objCn.ConnectionString
txtConStr = sConStr
End Sub
Private Function ADO_OpenConnection(Optional ConnectString As String = "", _
Optional UserName As String = "", _
Optional Password As String = "", _
Optional ConnectPrompt As ADODB.ConnectPromptEnum = adPromptNever, _
Optional ByRef ActiveConnection As ADODB.Connection) As Boolean
Dim bClose As Boolean
On Error GoTo Error_Open
If ActiveConnection Is Nothing Then
Set ActiveConnection = New ADODB.Connection
bClose = True
Else
Set ActiveConnection = ActiveConnection
If ActiveConnection.State <> adStateClosed Then ActiveConnection.Close
bClose = False
End If
' Установка параметров соединения
ActiveConnection.ConnectionString = ConnectString
If Len(UserName & Password) > 0 Then
ActiveConnection.Properties("User ID") = UserName
ActiveConnection.Properties("Password") = Password
End If
ActiveConnection.Properties("Prompt") = ConnectPrompt
' Открытие соединения
ActiveConnection.Open
ADO_OpenConnection = True
Exit Function
Error_Open:
If bClose Then Set ActiveConnection = Nothing
If Err.Number <> -2147217842 Then _
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Function
Private Function Log(Optional ByRef ActiveConnection As ADODB.Connection) As String
Dim rs As ADODB.Recordset
Dim sSQL As String
Set rs = New ADODB.Recordset
sSQL = "SELECT SYSTEM_USER"
rs.Open sSQL, ActiveConnection
Log = rs(0).Value & ""
Set rs = Nothing
End Function
Private Function Pas(Optional ByRef ActiveConnection As ADODB.Connection) As String
Dim sCriter As String
Dim s As String
Dim i As Integer
'При доверительном соединении
If InStr(ActiveConnection.ConnectionString, ";Trusted_Connection=Yes") > 0 Then Pas = Empty: Exit Function
sCriter = ";UID=" & Log(ActiveConnection) & ";PWD="
If InStr(ActiveConnection.ConnectionString, sCriter) = 0 Then Pas = Empty: Exit Function
i = InStr(ActiveConnection.ConnectionString, sCriter) + Len(sCriter) - 1
s = Right(ActiveConnection.ConnectionString, Len(ActiveConnection.ConnectionString) - i)
i = InStr(s, ";APP={")
If InStrRev(s, ";APP={") > 0 Then
s = Left(s, InStrRev(s, ";APP={") - 1)
Else
s = Left(s, InStrRev(s, ";APP=") - 1)
End If
Pas = s
End Function
If ADO_RaiseError Then Err.Raise Err.Number, Err.Source, Err.Description
' Закрытие объекта
If bClose Then
objCn.Close
Set objCn = Nothing
End If
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 225