Credit card data analysis using magnetic stripe reader using javascript

So, I have an html form that displays like this:

<span style='required'>*</span> - Indicates required field. <div class='fields'>Swiped Information</div> <input type=text name='swiped' id='swiped'> </div> <div class='fields'>First Name</div> <input type=text name='first_name' id='first_name'><span style='required'>*</span> </div> <div class='fields'>Last Name</div> <input type=text name='last_name' id='last_name'><span style='required'>*</span> </div> <div class='fields'>Expiration</div> <input type=text size=8 name='expiration' id='expiration'><span style='required'>*</span>(MMYY) </div> <div class='fields'>CVV Code</div> <input type=text size=8 name='cvv' id='cvv'><span style='required'>*</span> </div> <div class='fields'>Credit Card Number</div> <input type=text name='card' id='card'><span style='required'>*</span> </div> <hr> <div class='buttons'></div> <a onclick="readCard();" style="cursor:pointer; color:red;">Swipe Credit Card</a> </div> 

My knowledge of this kind of material is very poor. I have a basic small credit card reader that connects to a computer via USB. I want to be able to carry by credit card and my site to analyze the information in the form fields that are above.

I added the event onclick=readCard(); to the link below my form, and when it is clicked, a java script is launched to focus on the Swiped Information field, which will store the data string from the magnetic stripe reader.

 function readCard () { document.getElementById('swiped').focus(); } 

My thoughts are that the employee would hit the “Swipe Credit Card”, which would make the “Chip card information” field a focus and fill this field with a line, then javascript would break this information into pieces and fill out the form accordingly.

I searched high and low to try and find a solution, and closest I could find a tutorial that used asp.net as a language, and I can't do it. Either PHP or JavaScript. Thanks in advance.

All I have to do is split this long string into several and display the relevant parts in html form.

PS I'm not worried about the ATM checking the form, I will take care of it after I manage to fill out the form fields! Thanks!

UPDATE:

I created a JSFiddle, although the java script I inserted does not work. http://jsfiddle.net/r8FJX/

UPDATE:

In accordance with the comments below, I added an example of the data sent from my card reader to the computer. I went in and replaced every number in the line with randomly printed fake numbers and replaced my name with a fake one. (Sorry, scammers!)

 %B6545461234613451^DOE/JOHN^00000000000000000000000?;6545461234613451=984651465116111? 

I assume that, as the code laid out above, I can not find the documentation:

 %Bcardnumber^lastname/firstname^expDate?;cardnumber=expDate? 
+4
source share
4 answers

Option 1)

 var card_data = "%B6545461234613451^DOE/JOHN^00000000000000000000000?;6545461234613451=984651465116111?" var details1 = card_data.split("^"); var card_number = details1[0]; card_number = card_number.substring(2); var names = details1[1].split("/"); var first_name = names[1]; var last_name = names[0]; var details2 = details1[2].split(";"); details2 = details2[1].split("="); var exp_date = details2[1]; exp_date = exp_date.substring(0, exp_date.length - 1); exp_date = exp_date.substring(2, 3) + "/" + exp_date.substring(0,1); 

Option 2)

 var pattern=new RegExp("^\%B(\d+)\^(\w+)\/(\w+)\^\d+\?;\d+=(\d\d)(\d\d)\d+$"); var match = pattern.exec(card_data); card_number = match[1]; first_name = match[3]; last_name = match[2]; exp_date = match[5] + "/" + match[4]; 

Then Do:

 document.getElementById("first_name").value = first_name; document.getElementById("last_name").value = last_name; document.getElementById("card").value = card_number; document.getElementById("expiry").value = exp_date; 
+4
source

I had success with an expiration date:

exp_date = exp_date.substring (2, 4) + "/" + exp_date.substring (1, 3);

0
source

Only for future viewers like me who were looking. Duration must be adjusted. This will make the expiration date ... 10/18. Not 10/81, as I was getting ...

Below is the adjusted formatted date: 10/18 not 10/81 or 1/1

 exp_date = exp_date.substring(2, 4) + "/" + exp_date.substring(0,2); 
0
source

(For future people trying to analyze USB credit card reader data)

There are two (sometimes 3) data tracks, are they separated ? . The expiration date is duplicated on the first track and second track. If you want to read enough data to pay for a credit card, you can ignore the data from track 2 (everything from ; onwards).

CVC is not stored on magnetic stripe data. You will have to disable CVC verification in your payment processor. With Stripe, you can do this at https://dashboard.stripe.com/radar/rules .

 let parse = readerData => { let card = readerData.match(/%B([0-9]+)\^([AZ /.]+)\/([AZ /.]*)\^([0-9]{2})([0-9]{2})/); let lastName = card[2].trim(); // 'LASTNAME/FIRSTNAME.MR' is possible let firstName = card[3].trim().split('.')[0]; let fullName = `${firstName} ${lastName}`; return { exp_month: card[5], exp_year: card[4], number: card[1], name: fullName, }; } parse('%B6545461234613451^DOE/JOHN^21040000000000000000000?;this part does not matter') // {exp_month: "04", exp_year: "21", number: "6545461234613451", name: "JOHN DOE"} 

If you use Stripe.js v2 , you can pass the object returned by parse() directly to Stripe.card.createToken() .

I saw LASTNAME/FIRSTNAME MIDDLENAME in the sample data, this code should turn this into a FIRST MIDDLE LAST .

Read more at https://en.wikipedia.org/wiki/Magnetic_stripe_card#Financial_cards .

I do not know if this makes legal . New USB credit card readers encrypt the data they read (you need to send the data in their api (and pay for it) to decrypt it).

If you are having trouble with regex, try https://regex101.com/ to debug it.

0
source

All Articles