Antonariy писал(а):Автор походу тоже не ходил в математический кружок
Самый надежный способ - хранить в базе не просто поделенное/вычтенное число, а хеш пароля. Уровень доступа можно шифровать хешем (а еще лучше не хешем, а RSA), если значения уровня не используются внутри базы. Это запрещает хулиганить самому администратору под прикрытием чужого логина и одновременно не мешает менять уровни доступа.
как раз ходил.
взломщик просто скопирует его из ячейки админа в в свою ячейку и ему даже не надо знать, что там за число такое запрятано.
Option Explicit
Dim CrcTableInit As Boolean
Dim CRCTable(0 To 255) As Long
Dim lb1() As Byte
Dim lb2() As Byte
Public Function calcCRC32(ByteArray() As Byte) As Long
Dim i As Long
Dim crc As Long
Dim Z As Long
Dim t As Date
If CrcTableInit = False Then Call Init_CRCTable
crc = -1
For i = 0 To UBound(ByteArray) - 1
crc = (((crc And &HFFFFFF00) \ &H100) And &HFFFFFF) Xor (CRCTable((crc And &HFF) Xor ByteArray(i)))
crc = crc Xor ByteArray(i)
Next i
crc = crc Xor &HFFFFFFFF
calcCRC32 = crc
End Function
Private Sub Init_CRCTable()
Dim i As Long
Dim j As Long
Dim Limit As Long
Dim crc As Long
Limit = &HEDB88320
For i = 0 To 255
crc = i
For j = 0 To 7
If crc And 1 Then
crc = (((crc And &HFFFFFFFE) \ 2) And &H7FFFFFFF) Xor Limit
Else
crc = ((crc And &HFFFFFFFE) \ 2) And &H7FFFFFFF
End If
Next j
CRCTable(i) = crc
Next i
CrcTableInit = True
End Sub
Option Explicit
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private m_Key As String
Private m_sBox(0 To 255) As Integer
Private byteArray() As Byte
Private hiByte As Long
Private hiBound As Long
Public Function EncryptString(Text As String, Optional Key As String, Optional OutputInHex As Boolean) As String
Dim byteArray() As Byte
byteArray() = StrConv(Text, vbFromUnicode)
Call EncryptByte(byteArray(), Key)
EncryptString = StrConv(byteArray(), vbUnicode)
If OutputInHex = True Then EncryptString = EnHex(EncryptString)
End Function
Public Function DecryptString(Text As String, Optional Key As String, Optional IsTextInHex As Boolean) As String
Dim byteArray() As Byte
If IsTextInHex = True Then Text = DeHex(Text)
byteArray() = StrConv(Text, vbFromUnicode)
Call DecryptByte(byteArray(), Key)
DecryptString = StrConv(byteArray(), vbUnicode)
End Function
Public Sub EncryptByte(byteArray() As Byte, Optional Key As String)
Dim i As Long, j As Long, Temp As Byte, Offset As Long, OrigLen As Long, CipherLen As Long, CurrPercent As Long, NextPercent As Long, sBox(0 To 255) As Integer
If (Len(Key) > 0) Then Me.Key = Key
Call CopyMem(sBox(0), m_sBox(0), 512)
OrigLen = UBound(byteArray) + 1
CipherLen = OrigLen
For Offset = 0 To (OrigLen - 1)
i = (i + 1) Mod 256
j = (j + sBox(i)) Mod 256
Temp = sBox(i)
sBox(i) = sBox(j)
sBox(j) = Temp
byteArray(Offset) = byteArray(Offset) Xor (sBox((sBox(i) + sBox(j)) Mod 256))
If (Offset >= NextPercent) Then
CurrPercent = Int((Offset / CipherLen) * 100)
NextPercent = (CipherLen * ((CurrPercent + 1) / 100)) + 1
End If
Next
End Sub
Private Sub Reset()
hiByte = 0
hiBound = 1024
ReDim byteArray(hiBound)
End Sub
Private Sub Append(ByRef StringData As String, Optional Length As Long)
Dim DataLength As Long
If Length > 0 Then DataLength = Length Else DataLength = Len(StringData)
If DataLength + hiByte > hiBound Then
hiBound = hiBound + 1024
ReDim Preserve byteArray(hiBound)
End If
CopyMem ByVal VarPtr(byteArray(hiByte)), ByVal StringData, DataLength
hiByte = hiByte + DataLength
End Sub
Private Function DeHex(Data As String) As String
Dim iCount As Double
Reset
For iCount = 1 To Len(Data) Step 2
Append Chr$(Val("&H" & Mid$(Data, iCount, 2)))
Next
DeHex = GData
Reset
End Function
Private Function EnHex(Data As String) As String
Dim iCount As Double, sTemp As String
Reset
For iCount = 1 To Len(Data)
sTemp = Hex$(Asc(Mid$(Data, iCount, 1)))
If Len(sTemp) < 2 Then sTemp = "0" & sTemp
Append sTemp
Next
EnHex = GData
Reset
End Function
Private Property Get GData() As String
Dim StringData As String
StringData = Space(hiByte)
CopyMem ByVal StringData, ByVal VarPtr(byteArray(0)), hiByte
GData = StringData
End Property
Public Property Let Key(New_Value As String)
Dim a As Long, b As Long, Temp As Byte, Key() As Byte, KeyLen As Long
If (m_Key = New_Value) Then Exit Property
m_Key = New_Value
Key() = StrConv(m_Key, vbFromUnicode)
KeyLen = Len(m_Key)
For a = 0 To 255
m_sBox(a) = a
Next a
For a = 0 To 255
b = (b + m_sBox(a) + Key(a Mod KeyLen)) Mod 256
Temp = m_sBox(a)
m_sBox(a) = m_sBox(b)
m_sBox(b) = Temp
Next
End Property
Сейчас этот форум просматривают: Google-бот, Majestic-12 [Bot], Yandex-бот и гости: 27