Solved Copy & Paste loses last 7 characters.

HillTJ

To train a dog, first know more than the dog..
Local time
Yesterday, 18:42
Joined
Apr 1, 2019
Messages
731
All, I'm toying with a user 'Registration' form. I take the users email address and concatenate the hard drive serial to it, then run an RC5 cypher to come up with a "Password". All that works fine. Upon registration, my idea is that the user sends a system generated email that, of course includes their email & the HDD serial. I then run the cypher & return them a 'key'. The problem is that when I 'copy' the key to the 'RegisteredPWD' then the pasted string is missing the last few characters. Even if I do a straight copy/paste I cannot copy all the string. Yet if I run a quick update query to copy from 'PWD' to 'RegisteredPWD' then the copy/paste works and copies the complete string. I've included a screenshot of the dilemma. All seems to work if i use a shorter string to encrypt, say email address only, but I like the idea of tying the app to the user & PC.

Appreciate any insight.
Copy.Paste.jpg
 
1. Is the field in the table long enough to accommodate it?

2. Is the input on the form long enough to accommodate it?

To be clear I'm not talking visually. What are the underlying properties of each of those elements?
 
@plog , both PWD & RegisteredPWD are short text set @255 Characters. I made the form to illustrate the issue. Even if I directly copy/Paste within the table, the last 7 characters are missing. As I said, if I run an update query to copy from one to the other all works. It's something to do with the copy/paste.
 
Can you post an example app to show the issue
 
Even if I do a straight copy/paste I cannot copy all the string.
I suspect the data (RC5 key) is not really a string but rather an array of bytes. This would mean it can contain "characters", which are not allowed in strings (e.g. a string terminator). If this is the case, you should encode the data to a legitimate string.
 
@sonic8, i think you maybe right. When i encrypted only the email address i suspect i did not generate the offending character by luck rather than planning. I'll upload my database & you can see what i mean. Thanks
 
So, I've attached my database 'Password' my intention is to develop the code with this application then adapt to my 'real' project. Thus, no attempt to make it look good etc. It's also a repository of code that I'm playing with. The background is that 'frmMaster'opens upon startup (I've put some encode/decode fields on that form just to test what's going on). After 50 uses the code opens 'frmRegistration' but the user can register immediately from the button on 'frmmain' if they wish. Upon entering their email address in the unbound control on 'frmRegistration' & selecting 'Register' the underlying code saves a string (byte string?) to MsysUsers field 'PWD'. The string comprises their email address & HDD Serial #. The code then emails me & I send the user the same encoded string that they copy/paste from the email into their code. All done.

I'd be totally up for any suggestions. As I've said before, this is a test database only, to get the concept working. Make any changes that you see fit but please explain to me as I wish to learn.
 

Attachments

I am not totally clear what I need to do to replicate your issue.
Can you clarify what I need to test

Some initial observations:
1. The email feature doesn't work
2. Copying & pasting doesn't paste the entire string but the update query works correctly
3. In post #1, you said you were using RC5 but the code is for RC4

If it helps, I have an updated version of RC4 which fixes a couple of issues

If you are trying to encrypt both email address & hard drive numbers, you need a strategy for handling cases where one or both of those change for valid users
 
Colin,

The only form you need to worry about is 'frmRegistration'. Upon entering the firtsname, lastname & email address, then hitting 'Obtain Registration Key' my intention is to derive the password from email&HDD# then save it as [PWD] in table 'MsyUsers'. The email routine then runs and emails me the HDD #(I have their email address from the actual email). I then Concatenate email&HDD, run the encryption routine & send the 'key' via return email. You are correct it's an RC4 code. My problem was that I could not copy/paste the full string. Even after opening MsysUsers and copying directly (ctrl 'c' & ctrl 'v) from [PWD] to [RegisteredPWD]. The paste operation would always leave off several characters. Just try opening the table & copying/pasting. Appreciate it.

I added the update query just to test whether it was a copy/paste issue or a string issue. Really, the update query is of no other practical use.

Yes, if you've got a better rc4 then i'd appreciate a copy
 
Last edited:
again, i will offer you a "simple licensing" feature.
if you convert your db to .accde, then there is no need
to use "strong" encryption as in the case of RC4.

the first version of this db is using keys saved in table (MsysCode).

then on the next version, i moved all these codes to MsysResources table.

on this version i am storing the code in the VBA (collection class).
it doesn't use RC4, so the encrypted/decrypted text is within the ASCII table.
therefore you can copy and paste it.
 

Attachments

@arnelgp , yes final version will be .accde. Will certainly have a look at your version. Thanks.
 
FWIW, I provide a license key when customers purchase any of my commercial apps
In addition, for some apps, I also use an activation process.

When the app is first run, it collects info on the CPU, motherboard, hard drive and automatically emails that info to me.
An ActivationID is generated using parts of that data together with the license key & emailed back to the customer. This is stored in an encrypted form (though not using RC4!). Example: qhTMPNy`Lw]SNTPg^ba^MQSvPNdn

This was fairly complex to setup but it works reliably for the purpose

Anyway, as promised here is an updated RC4 function (attached)
 

Attachments

@isladogs , sounds similar to what i am trying to achieve. Will replace my rc4 code with yours and try again. Thanks

A question, why did you elect not to use an RC4 code on your applications?
 
I do use RC4 code for encryption in many places but also use other methods of encryption that are limited to the ASCII character set.
In some cases, I use more than one layer of encryption to prevent the same original characters being encrypted identically each time

For the purpose I mentioned RC4 wasn't needed. I can't remember whether I tried & rejected it for that task
If so, it wouldn't have worked for my customers as they need to copy the ActivationID from my email into the app

I suspect my replacement code may still have the same issues when you copy the characters.
If so, try changing the encryption key in case that circumvents the issue

Having said that, one of my security challenges involves users copying an RC4 encrypted string, decrypting it and opening a hidden web page:

messagebox.png

and that does work fine . . .
 
@isladogs , Colin, thanks. I've a lot to digest. I'm also looking at @arnelgp's example too & have a few questions for him. Thanks.
 
@arnelgp I get a variable Not defined error when compiling the following;

Code:
Public Function IDfromCode(ByVal code As String) As Integer
    Dim iKey As Integer
    
    For iKey = 1 To c.Count
        If c(iKey & "") = code Then
            Exit For
        End If
    Next
    IDfromCode = i
End Function

Not really sure as to how this was intended to work. I see that the license key is an encrypted version of the installation date. How is that provided to the user? Appreciate a bit of an explanation if you have the time. I see you use database properties - something I have been playing with & subject of a previous thread of mine.
 
i modify my database to look somewhat similar to what you have.
you will notice that there is that it is showing the Validation Code (WT4Z-SMVH) on the form.
you check the Validation code from the class, particularly on "v" collection and
determine the "key".
now lookup the key (which on first use is 1) on the k collection.
on immediate window, you Decrypt the key:

?Decrypt("B5F3F325539473B583")

and you will have: 4V1B-I54O

enter 4V1B-I54O to the Key textbox.

this is how you will send (e-mail) the key back to the user.
very simple.

everytime a successful key is entered, a New key will be used,
thus a New Validation Code also.

the Key (or database) is valid for 1 year (every year) from the date
of activation.
 

Attachments

@arnelgp , thank you. Will have a good look at it. Appreciate your help once again.
 
I see that the license key is an encrypted version of the installation date
i manually generate the key (see module1 for the code which saves it to a table).
the keys are not encrypted so you need to encrypt it first and save to the k collection.

same thing to generate the Validation code.
i generated 20 keys which is good for 20 years (if you apply a yearly subscription).

you can generate different keys for different clients.
therefore, you copy a different db to each different client.
 
@arnelgp, Brilliant!. Will adapt your method to suit my purpose. Really appreciate the time & effort all members have applied to this issue. If you don't mind, I will probably have additional questions as I absorb your technique. Thanks again.
 

Users who are viewing this thread

Back
Top Bottom