Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert string to binary

Status
Not open for further replies.

darkradar

Programmer
Jul 20, 2002
78
US
How to convert string to binary .
I tried the following cvar(Txtpassword).
But its not working. I am using this in Employee table where there are 2 fields .
user and Password. password is binary field. when user enters
password in the login screen it should convert it into binary
field. I am using VB6 and SQL Server 7.
thanks in advance.
 

A binary field is used for storing binary data like pictures, exe's, basically whole files. To store text in a binary field there is really no reason (or way) to convert text to binary since text is a representation of binary data. Take the letter A for example. Adding up its binary values = 65. What it looks like in binary is 01000001.

Do you get what I mean???

Good Luck

 
Hi

Actually I don't want password to be visible to all the
people who open the Employee table. I want password
to be stored in a different format other than text.
Is it possible to do like this. Because many users have
access to this table, and I don't want them to look at
the passwords.
 
darkrader, try this link:
-------------------------------------------------------------------------
-------------------------------------------------------------------------

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Univer
 
Here is also a standard number to binary converter code sample:
-------------------------------------------------------------------------
-------------------------------------------------------------------------

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Univer
 
im not too sure exactly what your after but you may be able to hide your data as follows,
here are 2 simple functions. one converts a byte to a binary string the other converts a binary string to an integer: (ps binary string is just what i call it, i dont think its a vb term)

so for example:-
Private Sub Command2_Click()
Dim mystring As String
Dim i As Integer
Dim temp As Byte
Dim bigbinary As String

mystring = "password"

For i = 1 To Len(mystring)
temp = Asc(Mid(mystring, i, 1))
bigbinary = bigbinary & ByteToBit(temp)
Next i

then to convert back use the bittodec function

End Sub

Private Function ByteToBit(myByte As Byte) As String

'Bit == 32103210
' --------
'&HF0 == "11110000"
'&H0A == "00001010"

Dim k As Integer
Dim x As Integer

Dim valofbyte As Integer
Dim mybytetobit As String

valofbyte = Val(CStr(myByte))
mybytetobit = ""

For k = 0 To 7
x = 2 ^ k
If valofbyte And x Then
mybytetobit = "1" & mybytetobit
Else
mybytetobit = "0" & mybytetobit
End If

Next k

ByteToBit = mybytetobit

End Function

Private Function BitToDec(MyBit As String) As Integer

' 32103210
' --------
'"00001010" == 10
'"11010100" == 212

Dim k As Integer
Dim x As Integer
Dim mybittodec As Integer
Dim myLength As Integer

myLength = Len(MyBit)

For k = 1 To myLength
If Mid(MyBit, k, 1) = 1 Then
x = 2 ^ (myLength - k)
mybittodec = mybittodec + x
End If
Next k

BitToDec = mybittodec
End Function

its not the most secure thing in the world but it closes prying eyes!

hope ive not wasted your time, good luck! If somethings hard to do, its not worth doing - Homer Simpson
 
sorry the command2 sub was missing some lines, here they are again

Private Sub Command2_Click()
Dim mystring As String
Dim i As Integer
Dim temp As Byte
Dim bigbinary As String
Dim convert As String
Dim password As String

mystring = "password"

For i = 1 To Len(mystring)
temp = Asc(Mid(mystring, i, 1))
bigbinary = bigbinary & ByteToBit(temp)
Next i

For i = 0 To Len(bigbinary) - 1
convert = Mid(bigbinary, i * 8 + 1, 8)
password = password & Chr(BitToDec(convert))
Next i

End Sub

good luck If somethings hard to do, its not worth doing - Homer Simpson
 
I love these questions.
EVERYTHING in your computer is binary. Unless you have some new wizz bang quantum computer that each bit holds 26 different states.

So your requirement isn't that you want the password to be held in binary, because it already is. But that the password is not readible by others. This is called encryption. Typically the easiest thing to do is a 1 way hash, search the net there is heaps of algorithms to do this. The user enters their password in and it goes throught the 1 way hash and the result is stored in the database. Everytime they log in the password they entered is run through the hash and compaired to the database. Get a match you are let in. No match and you are not. 1 way hash systems can not be reversed. Ie you can not derive the original password from the hashed one. This means if the person forgets the password an admin has to reset it as even the admin can not find out what the password is.

You could use an encryption/decryption to store the password but this makes it less secure as finding out that encryption routine often isn't that difficult.

The 1 way hash can be brute forced but realistically you can overcome that problem easily enough.

Storing a password like AdamAndEve as 0x4164616D416E64457665 is only going to stop the most stupid of hackers. Infact if someone has access to the table and knows their own password it becomes very trivial even with bit shifting etc.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top