changing text to numeric & back

NigelShaw

Registered User.
Local time
Today, 10:33
Joined
Jan 11, 2008
Messages
1,575
Hi,

i am wanting to change a text string to a numeric and im not sure where to start. the reason for this is to store a text password that is coded so it cannot be copied but brought back to text for verification.

there are probsbly better ways than this which i am open to but not entirely sure where to start on this. any ideas on where i can look to start this?


many thanks,


Nigel
 
Hi,

i am wanting to change a text string to a numeric and im not sure where to start. the reason for this is to store a text password that is coded so it cannot be copied but brought back to text for verification.

there are probsbly better ways than this which i am open to but not entirely sure where to start on this. any ideas on where i can look to start this?


many thanks,


Nigel


Nigel,

Sounds like you need to encrypt and decrypt a string. This will not prevent the data from being copied, but it will prevent the data from being read by a human.


Here is a very simple example:

Code:
Public Function XORDecryption(CodeKey As String, DataIn As String) As String
    
    Dim lonDataPtr As Long
    Dim strDataOut As String
    Dim intXOrValue1 As Integer
    Dim intXOrValue2 As Integer
    

    For lonDataPtr = 1 To (Len(DataIn) / 2)
        'The first value to be XOr-ed comes from the data to be encrypted
        intXOrValue1 = Val("&H" & (Mid$(DataIn, (2 * lonDataPtr) - 1, 2)))
        'The second value comes from the code key
        intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1))
        
        strDataOut = strDataOut + Chr(intXOrValue1 Xor intXOrValue2)
    Next lonDataPtr
   XORDecryption = strDataOut
End Function


Public Function XOREncryption(CodeKey As String, DataIn As String) As String
    
    Dim lonDataPtr As Long
    Dim strDataOut As String
    Dim temp As Integer
    Dim tempstring As String
    Dim intXOrValue1 As Integer
    Dim intXOrValue2 As Integer
    

    For lonDataPtr = 1 To Len(DataIn)
        'The first value to be XOr-ed comes from the data to be encrypted
        intXOrValue1 = Asc(Mid$(DataIn, lonDataPtr, 1))
        'The second value comes from the code key
        intXOrValue2 = Asc(Mid$(CodeKey, ((lonDataPtr Mod Len(CodeKey)) + 1), 1))
        
        temp = (intXOrValue1 Xor intXOrValue2)
        tempstring = Hex(temp)
        If Len(tempstring) = 1 Then tempstring = "0" & tempstring
        
        strDataOut = strDataOut + tempstring
    Next lonDataPtr
   XOREncryption = strDataOut
End Function

'USAGE
'Private Sub cmdEncryptdecrypt_Click()
'    Dim strCodeKey As String
'    strCodeKey = InputBox("Please enter your password", "XOr Encryption")
'    txtSource.Text = XOREncryption(strCodeKey, txtSource.Text)
'End Sub
'
'Private Sub cmdDecryptdecrypt_Click()
'    Dim strCodeKey As String
'    strCodeKey = InputBox("Please enter your password", "XOr Decryption")
'    txtSource.Text = XORDecryption(strCodeKey, txtSource.Text)
'End Sub
 
Hi HiTech,

thanks for your code sample. i have tried it and just a little confused. In the usage section, you have the subs Encryptdecrypt & Decryptencrypt.

how do you link this to a form textbox?


thanks

nigel
 
Hi HiTech,

thanks for your code sample. i have tried it and just a little confused. In the usage section, you have the subs Encryptdecrypt & Decryptencrypt.

how do you link this to a form textbox?


thanks

nigel

Depends on what you want to do.

The basics are:

1) before storing the data, you will run: Encryptdecrypt

2) Before using the data, you will run: Decryptencrypt
 
Hi again,

i appreciate that. what i am doing is setting a password that cannot be read by looking at it. so i want to create a sample where i set the password and a textbox shows the the result. from here, i know what i can do to save the value that is shown as i will change it over to a variable.

i dont understand the textsource.text

thanks,

Nigel
 
Nigel,

Just go to the field, right-click --> Properties.

Set the Input Mask to "Password".

Is that what you want?

The --> textsource.text is only available when the user is entering data.
As the user types in EACH character this value will be available in the
OnChange event. I don't think that's what you want.

hth,
Wayne
 
Hi

What I want to do is store an encrypted version of a password and decrypt it when it needs verifying.

Nigel
 
Hi HiTech

I see now. That's great thanks. What I am doing is saving the encrypted code to the registry in a deeply hidden key. I will set the keycode in my module and then save / retrieve using your encrypt decrypt.

Many thanks :)

Nigel
 
Why are you saving the the key to the registry? why not save it to a db.property?

Is this a user login password that is user specific or is it an security password?

David
 
Hi David,

i was writing the data to the registry because i wanted it well hidden. when my db starts, it will check the registry key against the listed username. if they match, it will continue to the login where the passwords will will be checked. if these march, the user will be allowed into the program.

i decided on the registry as the data is 100% kept when the db is closed. it would be harder to find there rather than a file in the db folder. also, whe nmy program starts, if the registry key is not there or the decrypted code does not match the credentials, the program bails and emails the IT admin.

lastly, i havent looked much into db.property. is this an internal thing or by means of adding external sources like text files into the db itself as a reference?


regards,

Nigel
 
it will check the registry key against the listed username.

Your first point about looking in the registry for a user name to compare with what the person has typed in is ok, however, does this not limit the user to a specific workstation(s)?

What happens when you get a new user or a user leaves? Do you have to update the registry each time? bit of an overkill, me thinks.

With regard to db.Properties you can define save and recall data items to the general properties of any mdb. In much the same way that you create registry keys. You can store different types of information in there such as version number, serial number, copywrite details, hits, BE paths, etc. Because you can give them any name you want prying eyes don't know of their existance. I tend to use them for evaluation copies, whereby I set a counter up and when it opens the mdb it increases the counter by one and checks against the max open times (another property it defined) if it exceeds this then the user cannot open the mdb. and unless you know the actual name of the property you cannot change or reset it.

If you would like examples I can send you some.

David
 
Hi David,

the program is specific to 1 user only which is the requirement however, i can see your point of replaced users. i do a module set up to change the user settings in the registry but i would agree that it is possibly an overkill.

if you could send some samples, that would be great. it would give me an insight into db.properties as i have not really looked at this before.

many thanks for your interest.


Nigel
 
Hi David,

the program is specific to 1 user only which is the requirement however, i can see your point of replaced users. i do a module set up to change the user settings in the registry but i would agree that it is possibly an overkill.

if you could send some samples, that would be great. it would give me an insight into db.properties as i have not really looked at this before.

many thanks for your interest.


Nigel

We talked about using databases properties before with Mike375.

I posted example code in this previous thread here :

Stopping DB after "free trial" etc
 

Users who are viewing this thread

Back
Top Bottom