I'm building a mobile application that transfers points between users via QRCode. I'm concerned about security and am looking for effective simple yes secure algorithm to use. The scenario should be something similar to this.
- User A wants to transfer X points to User B.
- User A generates a QR code on his mobile application, embeds the points number(
X
) anduserA.id
in the QR code. - User B reads the QR code, sends {
points numver:X
,from=userA.id
,to=userB.id
} to the server. - User
A
can generate the QRCode while offline, where userB
must be online to read the QRCode. - The server receives the request and transfers
X
points from userA
to userB
.
The technical scenario we have for making this:
- The server has a global value named
salt
.salt
is random and auto generated every day. - In the server, every user has the following fields:
- id: Auto Incriminate number.
- userKey:
md5( id + salt )
=> changes every day. - generatedQRCodesNumberForToday: a number represents how many times the user generated a QRCode today, max value is 10, the value resets every day.
- N: Array of already uses numbers in the current day while transferring points, the array resets everyday.
- Every day, the user claims a new
userKey
. - Every user have a counter in his mobile application represents
generatedQRCodesNumberForToday
, this number is synced with the server whenever the user is online, and this number increases whenever the user creates an new QRCode. - If user
A
wants to transferX
points to userB
:- User
A
creates a QRCode that has {from:userA.id
,numberOfTrile:md5(userA.userKey + userA.generatedQRCodesNumberForToday)
,points:encode(userA.pointsToTransfer, userA.userKey)
}. - User
B
reads the qr data, addsto:userB.id
to them, and sends them to the server.
- User
- On server side:
- The server receives the
from
field and knows who is the sender. - The server receives the
to
field and knows who is the receiver. - The server receives the
points
field and decodes is using the senderuserKey
to know the amount of points. - The server receives
numberOfTrile
field. The use ofnumberOfTrile
field is to make sure that no user will generate the same QRCode more than once. The server tries to matchnumberOfTrile
with {md5(from.userKey + '1')
,...,md5(from.userKey + N)
,...,md5(from.userKey + '10')
} whereN
was not used before, if there's a match then the transform process is approved and the number that matched the concatenationN
is marked as not valid for future use.
- The server receives the
I want to know if my process is secure or it has any possible security vulnerabilities.