By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,508 Members | 1,823 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,508 IT Pros & Developers. It's quick & easy.

Can MS Access interface with Smart Cards?

twinnyfo
Expert Mod 2.5K+
P: 3,282
Hey Friends!

Does anyone know if MS Access can interface with Smart Cards? I've done about a half-day of searching and have found nothing specific to what I am looking for.

I want Access to be able to pull up the data on a Smart Card and request the user validate their identity using their PIN (a 4-8 digit code that every user is required to have with their Smart Card) and then, once their identity is validated, this could "lock" a record from editing. This would be nothing more than changing a Yes/No flag in the record. Then, once the record is locked, the only person who could unlock and edit the record would be the same person--again, using validation from their Smart Card. (I know that Access does not have fool-proof security)

I am sure this is not inherent with the standard tools in Access and probably requires some advanced playing with APIs or DLLs, which are not my forté, but I'm willing to try. I just don't know where to start.

Anyone have any experience or ideas on this one?

Warmest regards,
twinnyfo
May 30 '13 #1
Share this Question
Share on Google+
4 Replies


Oralloy
Expert 100+
P: 983
twinnyfo,

Try to get a code example from your smart-card vendor. The language really doesn't matter, as the sequence of calls and responses is the critical part. Once you have the code, we can construct a DLL interface and just hoist the example into VBA.

I'm pretty sure you will have no problems dealing with the database, from the your other posts that I've seen.

Luck!
Oralloy
May 30 '13 #2

twinnyfo
Expert Mod 2.5K+
P: 3,282
Isn't there a way to simply check the current system to see if there is a Card inserted, and then, scan the card to see what is available? Much like Adobe Acrobat allows Smart Card signatures, regardless of who the vendor is--when I add a signature to a PDF document, it just "knows" what to look for. This is more along the lines of what I am trying to do.

Make sense?
May 31 '13 #3

Oralloy
Expert 100+
P: 983
twinnyfo,

Makes sense.

I haven't actually programmed smart-card access, so we are learning together.

As for simple ways, yes, there are - it looks like MSDN examples are the way you might need to go.

I found this smart-card discussion on the MSDN site. It has examples in several languages, including some VBA. It has a download of the samples at the top, so it is likely a very good starting place.

See if that is what you need to get started. Meanwhile, I'll keep looking around.

Luck!
Oralloy
May 31 '13 #4

Oralloy
Expert 100+
P: 983
twinnyfo,

Here is some VBA code that I cribbed from HERE, although you might want to read the thread, as it is oriented towards a specific reader - I think the DLL interface is sufficiently portable, however.

Expand|Select|Wrap|Line Numbers
  1. '**************************************************************************
  2. ' winscard.dll Visual Basic Function Prototypes
  3. '**************************************************************************
  4. 'SCardAccessStartedEvent
  5. 'http://msdn.microsoft.com/en-us/library/aa379466(VS.85).aspx
  6. 'HANDLE STDCALL SCardAccessStartedEvent(VOID)
  7. Public Declare Function SCardAccessStartedEvent Lib "winscard.dll" () As Long
  8.  
  9. 'SCardAddReaderToGroup
  10. 'http://msdn.microsoft.com/en-us/library/aa379468(VS.85).aspx
  11. 'LONG STDCALL SCardAddReaderToGroupA(SCARDCONTEXT(in), LPCSTR(in), LPCSTR(in))
  12. Public Declare Function SCardAddReaderToGroup Lib "winscard.dll" Alias "SCardAddReaderToGroupA" ( _
  13.     ByVal hContext As Long, _
  14.     ByVal szReaderName As String, _
  15.     ByVal szGroupName As String _
  16.     ) As Long
  17.  
  18. 'SCardBeginTransaction
  19. 'http://msdn.microsoft.com/en-us/library/aa379469(VS.85).aspx
  20. 'LONG STDCALL SCardBeginTransaction(SCARDHANDLE(in))
  21. Public Declare Function SCardBeginTransaction Lib "winscard.dll" ( _
  22.     ByVal hCard As Long _
  23.     ) As Long
  24.  
  25. 'SCardCancel
  26. 'http://msdn.microsoft.com/en-us/library/aa379470(VS.85).aspx
  27. 'LONG STDCALL SCardCancel(SCARDCONTEXT(in))
  28. Public Declare Function SCardCancel Lib "winscard.dll" ( _
  29.     ByVal hContext As Long _
  30.     ) As Long
  31.  
  32. 'SCardConnect
  33. 'http://msdn.microsoft.com/en-us/library/aa379473(VS.85).aspx
  34. 'LONG STDCALL SCardConnectA(SCARDCONTEXT(in), LPCSTR(in), DWORD(in), DWORD(in),
  35. ' LPSCARDHANDLE(out), LPDWORD(out))
  36. Public Declare Function SCardConnect Lib "winscard.dll" Alias "SCardConnectA" ( _
  37.     ByVal hContext As Long, _
  38.     ByVal szReader As String, _
  39.     ByVal dwShareMode As Long, _
  40.     ByVal dwPreferredProtocols As Long, _
  41.     ByRef phCard As Long, _
  42.     ByRef pdwActiveProtocol As Long _
  43.     ) As Long
  44.  
  45. 'SCardControl
  46. 'http://msdn.microsoft.com/en-us/library/aa379474(VS.85).aspx
  47. 'LONG STDCALL SCardControl(SCARDHANDLE(in), DWORD(in), LPCVOID(in), DWORD(in),
  48. ' LPVOID(out), DWORD(in), LPDWORD(out))
  49. Public Declare Function SCardControl Lib "winscard.dll" ( _
  50.     ByVal hCard As Long, _
  51.     ByVal dwControlCode As Long, _
  52.     ByRef lpInBuffer As Long, _
  53.     ByVal nInBufferSize As Long, _
  54.     ByRef lpOutBuffer As Long, _
  55.     ByVal nOutBufferSize As Long, _
  56.     ByRef lpBytesReturned As Long _
  57.     ) As Long
  58.  
  59. 'SCardDisconnect
  60. 'http://msdn.microsoft.com/en-us/library/aa379475(VS.85).aspx
  61. 'LONG STDCALL SCardDisconnect(SCARDHANDLE(in), DWORD(in))
  62. Public Declare Function SCardDisconnect Lib "winscard.dll" ( _
  63.     ByVal hCard As Long, _
  64.     ByVal dwDisposition As Long _
  65.     ) As Long
  66.  
  67. 'SCardEndTransaction
  68. 'http://msdn.microsoft.com/en-us/library/aa379477(VS.85).aspx
  69. 'LONG STDCALL SCardEndTransaction(SCARDHANDLE(in), DWORD(in))
  70. Public Declare Function SCardEndTransaction Lib "winscard.dll" ( _
  71.     ByVal hCard As Long, _
  72.     ByVal dwDisposition As Long _
  73.     ) As Long
  74.  
  75. 'SCardEstablishContext
  76. 'http://msdn.microsoft.com/en-us/library/aa379479(VS.85).aspx
  77. 'LONG STDCALL SCardEstablishContext(DWORD(in), LPCVOID(in), LPCVOID(in),
  78. ' LPSCARDCONTEXT(out))
  79. Public Declare Function SCardEstablishContext Lib "winscard.dll" ( _
  80.     ByVal dwScope As Long, _
  81.     ByVal pvReserved1 As Long, _
  82.     ByVal pvReserved2 As Long, _
  83.     ByRef phContext As Long _
  84.     ) As Long
  85.  
  86. 'SCardForgetCardType
  87. 'http://msdn.microsoft.com/en-us/library/aa379482(VS.85).aspx
  88. 'LONG STDCALL SCardForgetCardTypeA(SCARDCONTEXT(in), LPCSTR(in))
  89. Public Declare Function SCardForgetCardType Lib "winscard.dll" Alias "SCardForgetCardTypeA" ( _
  90.     ByVal hContext As Long, _
  91.     ByVal szCardName As String _
  92.     ) As Long
  93.  
  94. 'SCardForgetReader
  95. 'http://msdn.microsoft.com/en-us/library/aa379484(VS.85).aspx
  96. 'LONG STDCALL SCardForgetReaderA(SCARDCONTEXT(in), LPCSTR(in))
  97. Public Declare Function SCardForgetReader Lib "winscard.dll" Alias "SCardForgetReaderA" ( _
  98.     ByVal hContext As Long, _
  99.     ByVal szReaderName As String _
  100.     ) As Long
  101.  
  102. 'SCardForgetReaderGroup
  103. 'http://msdn.microsoft.com/en-us/library/aa379486(VS.85).aspx
  104. 'LONG STDCALL SCardForgetReaderGroupA(SCARDCONTEXT(in), LPCSTR(in))
  105. Public Declare Function SCardForgetReaderGroup Lib "winscard.dll" Alias "SCardForgetReaderGroupA" ( _
  106.     ByVal hContext As Long, _
  107.     ByVal szGroupName As String _
  108.     ) As Long
  109.  
  110. 'SCardFreeMemory
  111. 'http://msdn.microsoft.com/en-us/library/aa379488(VS.85).aspx
  112. 'LONG STDCALL SCardFreeMemory(SCARDCONTEXT(in), LPCVOID(in))
  113. Public Declare Function SCardFreeMemory Lib "winscard.dll" ( _
  114.     ByVal hContext As Long, _
  115.     ByVal pvMem As Long _
  116.     ) As Long
  117.  
  118. 'SCardGetAttrib
  119. 'http://msdn.microsoft.com/en-us/library/aa379559(VS.85).aspx
  120. 'LONG STDCALL SCardGetAttrib(SCARDHANDLE(in), DWORD(in), LPBYTE(out), LPDWORD(inout))
  121. Public Declare Function SCardGetAttrib Lib "winscard.dll" ( _
  122.     ByVal hCard As Long, _
  123.     ByVal dwAttrId As Long, _
  124.     ByRef pbAttr As ByteArray, _
  125.     ByRef pcbAttrLen As Long _
  126.     ) As Long
  127.  
  128. 'SCardGetCardTypeProviderName
  129. 'http://msdn.microsoft.com/en-us/library/aa379655(VS.85).aspx
  130. 'LONG STDCALL SCardGetCardTypeProviderNameA(SCARDCONTEXT(in), LPCSTR(in), DWORD(in),
  131. ' LPSTR(out), LPDWORD(inout))
  132. Public Declare Function SCardGetCardTypeProviderName Lib "winscard.dll" Alias "SCardGetCardTypeProviderNameA" ( _
  133.     ByVal hContext As Long, _
  134.     ByVal szCardName As String, _
  135.     ByVal dwProviderId As Long, _
  136.     ByVal szProvider As String, _
  137.     ByRef pcchProvider As Long _
  138.     ) As Long
  139.  
  140. 'SCardGetProviderId
  141. 'http://msdn.microsoft.com/en-us/library/aa379761(VS.85).aspx
  142. 'LONG STDCALL SCardGetProviderIdA(SCARDCONTEXT(in), LPCSTR(in), LPGUID(out))
  143. Public Declare Function SCardGetProviderId Lib "winscard.dll" Alias "SCardGetProviderIdA" ( _
  144.     ByVal hContext As Long, _
  145.     ByVal szCard As String, _
  146.     ByRef pguidProviderId As GUID _
  147.     ) As Long
  148.  
  149. 'SCardGetStatusChange
  150. 'http://msdn.microsoft.com/en-us/library/aa379773(VS.85).aspx
  151. 'LONG STDCALL SCardGetStatusChangeA(SCARDCONTEXT(in), DWORD(in),
  152. ' LPSCARD_READERSTATEA(inout), DWORD(in))
  153. Public Declare Function SCardGetStatusChange Lib "winscard.dll" Alias "SCardGetStatusChangeA" ( _
  154.     ByVal hContext As Long, _
  155.     ByVal dwTimeout As Long, _
  156.     ByRef rgReaderStates() As SCARD_READERSTATE, _
  157.     ByVal cReaders As Long _
  158.     ) As Long
  159.  
  160. 'SCardIntroduceCardType
  161. 'http://msdn.microsoft.com/en-us/library/aa379784(VS.85).aspx
  162. 'LONG STDCALL SCardIntroduceCardTypeA(SCARDCONTEXT(in), LPCSTR(in), LPCGUID(in),
  163. ' LPCGUID(in), DWORD(in), LPCBYTE(in), LPCBYTE(in), DWORD(in))
  164. Public Declare Function SCardIntroduceCardType Lib "winscard.dll" Alias "SCardIntroduceCardTypeA" ( _
  165.     ByVal hContext As Long, _
  166.     ByVal szCardName As String, _
  167.     ByRef pguidPrimaryProvider As GUID, _
  168.     ByRef pguidInterfaces As GUID, _
  169.     ByVal dwInterfaceCount As Long, _
  170.     ByVal pbAtr As ByteArray, _
  171.     ByVal pbAtrMask As ByteArray, _
  172.     ByVal cbAtrLen As Long _
  173.     ) As Long
  174.  
  175. 'SCardIntroduceReader
  176. 'http://msdn.microsoft.com/en-us/library/aa379786(VS.85).aspx
  177. 'LONG STDCALL SCardIntroduceReaderA(SCARDCONTEXT(in), LPCSTR(in), LPCSTR(in))
  178. Public Declare Function SCardIntroduceReader Lib "winscard.dll" Alias "SCardIntroduceReaderA" ( _
  179.     ByVal hContext As Long, _
  180.     ByVal szReaderName As String, _
  181.     ByVal szDeviceName As String _
  182.     ) As Long
  183.  
  184. 'SCardIntroduceReaderGroup
  185. 'http://msdn.microsoft.com/en-us/library/aa379787(VS.85).aspx
  186. 'LONG STDCALL SCardIntroduceReaderGroupA(SCARDCONTEXT(in), LPCSTR(in))
  187. Public Declare Function SCardIntroduceReaderGroup Lib "winscard.dll" Alias "SCardIntroduceReaderGroupA" ( _
  188.     ByVal hContext As Long, _
  189.     ByVal szGroupName As String _
  190.     ) As Long
  191.  
  192. 'SCardIsValidContext
  193. 'http://msdn.microsoft.com/en-us/library/aa379788(VS.85).aspx
  194. 'LONG STDCALL SCardIsValidContext(SCARDCONTEXT(in))
  195. Public Declare Function SCardIsValidContext Lib "winscard.dll" ( _
  196.     ByVal hContext As Long _
  197. ) As Long
  198.  
  199. 'SCardListCards
  200. 'http://msdn.microsoft.com/en-us/library/aa379789(VS.85).aspx
  201. 'LONG STDCALL SCardListCardsA(SCARDCONTEXT(in), LPCBYTE(in), LPCGUID(in), DWORD(in),
  202. ' LPCSTR(out), LPDWORD(inout))
  203. Public Declare Function SCardListCards Lib "winscard.dll" Alias "SCardListCardsA" ( _
  204.     ByVal hContext As Long, _
  205.     ByVal pbAtr As ByteArray, _
  206.     ByVal rgguidInterfaces As Long, _
  207.     ByVal cguidInterfaceCount As Long, _
  208.     ByVal mszCards As String, _
  209.     ByRef pcchCards As Long _
  210.     ) As Long
  211.  
  212. 'SCardListInterfaces
  213. 'http://msdn.microsoft.com/en-us/library/aa379790(VS.85).aspx
  214. 'LONG STDCALL SCardListInterfacesA(SCARDCONTEXT(in), LPCSTR(in), LPGUID(out),
  215. ' LPDWORD(inout))
  216. Public Declare Function SCardListInterfaces Lib "winscard.dll" Alias "SCardListInterfacesA" ( _
  217.     ByVal hContext As Long, _
  218.     ByVal szCard As String, _
  219.     ByRef pguidInterfaces As GUID, _
  220.     ByRef pcguidInterfaces As Long _
  221.     ) As Long
  222.  
  223. 'SCardListReaderGroups
  224. 'http://msdn.microsoft.com/en-us/library/aa379792(VS.85).aspx
  225. 'LONG STDCALL SCardListReaderGroupsA(SCARDCONTEXT(in), LPSTR(out), LPDWORD(inout))
  226. Public Declare Function SCardListReaderGroups Lib "winscard.dll" Alias "SCardListReaderGroupsA" ( _
  227.     ByVal hContext As Long, _
  228.     ByVal mszGroups As String, _
  229.     ByRef pcchGroups As Long _
  230.     ) As Long
  231.  
  232. 'SCardListReaders
  233. 'http://msdn.microsoft.com/en-us/library/aa379793(VS.85).aspx
  234. 'LONG STDCALL SCardListReadersA(SCARDCONTEXT(in), LPCSTR(in), LPSTR(out), LPDWORD(inout))
  235. Public Declare Function SCardListReaders Lib "winscard.dll" Alias "SCardListReadersA" ( _
  236.     ByVal hContext As Long, _
  237.     ByVal mszGroups As String, _
  238.     ByVal mszReaders As String, _
  239.     ByRef pcchReaders As Long _
  240.     ) As Long
  241.  
  242. 'SCardLocateCards
  243. 'http://msdn.microsoft.com/en-us/library/aa379794(VS.85).aspx
  244. 'LONG STDCALL SCardLocateCardsA(SCARDCONTEXT(in), LPCSTR(in),
  245. ' LPSCARD_READERSTATEA(inout), DWORD(in))
  246. Public Declare Function SCardLocateCards Lib "winscard.dll" Alias "SCardLocateCardsA" ( _
  247.     ByVal hContext As Long, _
  248.     ByVal mszCards As String, _
  249.     ByRef rgReaderStates() As SCARD_READERSTATE, _
  250.     ByVal cReaders As Long _
  251.     ) As Long
  252.  
  253. 'SCardLocateCardsByATR
  254. 'http://msdn.microsoft.com/en-us/library/aa379796(VS.85).aspx
  255. 'LONG STDCALL SCardLocateCardsByATRA(SCARDCONTEXT(in), LPSCARD_ATRMASK(in), DWORD(in),
  256. ' LPSCARD_READERSTATEA(inout), DWORD(in))
  257. Public Declare Function SCardLocateCardsByATR Lib "winscard.dll" Alias "SCardLocateCardsByATRA" ( _
  258.     ByVal hContext As Long, _
  259.     ByRef rgAtrMasks() As SCARD_ATRMASK, _
  260.     ByVal cAtrs As Long, _
  261.     ByRef rgReaderStates() As SCARD_READERSTATE, _
  262.     ByVal cReaders As Long _
  263.     ) As Long
  264.  
  265. 'SCardReconnect
  266. 'http://msdn.microsoft.com/en-us/library/aa379797(VS.85).aspx
  267. 'LONG STDCALL SCardReconnect(SCARDHANDLE(in), DWORD(in), DWORD(in), DWORD(in),
  268. ' LPDWORD(out))
  269. Public Declare Function SCardReconnect Lib "winscard.dll" ( _
  270.     ByVal hCard As Long, _
  271.     ByVal dwShareMode As Long, _
  272.     ByVal dwPreferredProtocols As Long, _
  273.     ByVal dwInitialization As Long, _
  274.     ByRef pdwActiveProtocol As Long _
  275.     ) As Long
  276.  
  277. 'SCardReleaseContext
  278. 'http://msdn.microsoft.com/en-us/library/aa379798(VS.85).aspx
  279. 'LONG STDCALL SCardReleaseContext(SCARDCONTEXT(in))
  280. Public Declare Function SCardReleaseContext Lib "winscard.dll" ( _
  281.     ByVal hContext As Long _
  282.     ) As Long
  283.  
  284. 'SCardReleaseStartedEvent
  285. 'http://msdn.microsoft.com/en-us/library/aa379799(VS.85).aspx
  286. 'VOID STDCALL SCardReleaseStartedEvent(HANDLE(in))
  287. Public Declare Sub SCardReleaseStartedEvent Lib "winscard.dll" ( _
  288.     ByVal hStartedEventHandle As Long _
  289.     )
  290.  
  291. 'SCardRemoveReaderFromGroup
  292. 'http://msdn.microsoft.com/en-us/library/aa379800(VS.85).aspx
  293. 'LONG STDCALL SCardRemoveReaderFromGroupA(SCARDCONTEXT(in), LPCSTR(in), LPCSTR(in))
  294. Public Declare Function SCardRemoveReaderFromGroup Lib "winscard.dll" Alias "SCardRemoveReaderFromGroupA" ( _
  295.     ByVal hContext As Long, _
  296.     ByVal szReaderName As String, _
  297.     ByVal szGroupName As String _
  298.     ) As Long
  299.  
  300. 'SCardSetAttrib
  301. 'http://msdn.microsoft.com/en-us/library/aa379801(VS.85).aspx
  302. 'LONG STDCALL SCardSetAttrib(SCARDHANDLE(in), DWORD(in), LPCBYTE(in), DWORD(in))
  303. Public Declare Function SCardSetAttrib Lib "winscard.dll" ( _
  304.     ByVal hCard As Long, _
  305.     ByVal dwAttrId As Long, _
  306.     ByVal pbAttr As ByteArray, _
  307.     ByVal cbAttrLen As Long _
  308.     ) As Long
  309.  
  310. 'SCardSetCardTypeProviderName
  311. 'http://msdn.microsoft.com/en-us/library/aa379802(VS.85).aspx
  312. 'LONG STDCALL SCardSetCardTypeProviderNameA(SCARDCONTEXT(in), LPCSTR(in), DWORD(in),
  313. ' LPCSTR(in))
  314. Public Declare Function SCardSetCardTypeProviderName Lib "winscard.dll" Alias "SCardSetCardTypeProviderNameA" ( _
  315.     ByVal hContext As Long, _
  316.     ByVal szCardName As String, _
  317.     ByVal dwProviderId As Long, _
  318.     ByVal szProvider As String _
  319.     ) As Long
  320.  
  321. 'SCardState
  322. 'LONG STDCALL SCardState(SCARDHANDLE(in), LPDWORD(out), LPDWORD(out), LPBYTE(out),
  323. ' LPDWORD(out))
  324. Public Declare Function SCardState Lib "winscard.dll" ( _
  325.     ByVal hCard As Long, _
  326.     ByRef pdwState As Long, _
  327.     ByRef pdwProtocol As Long, _
  328.     ByRef pbAtr As ByteArray, _
  329.     ByRef pcbAtrLen As Long _
  330. ) As Long
  331.  
  332. 'SCardStatus
  333. 'http://msdn.microsoft.com/en-us/library/aa379803(VS.85).aspx
  334. 'LONG STDCALL SCardStatusA(SCARDHANDLE(in), LPSTR(out), LPDWORD(inout), LPDWORD(out),
  335. ' LPDWORD(out), LPBYTE(out), LPDWORD(inout))
  336. Public Declare Function SCardStatus Lib "winscard.dll" Alias "SCardStatusA" ( _
  337.     ByVal hCard As Long, _
  338.     ByVal szReaderName As String, _
  339.     ByRef pcchReaderLen As Long, _
  340.     ByRef pdwState As Long, _
  341.     ByRef pdwProtocol As Long, _
  342.     ByRef pbAtr As ByteArray, _
  343.     ByRef pcbAtrLen As Long _
  344.     ) As Long
  345.  
  346. 'SCardTransmit
  347. 'http://msdn.microsoft.com/en-us/library/aa379804.aspx
  348. 'LONG STDCALL SCardTransmit(SCARDHANDLE(in), LPCSCARD_IO_REQUEST(in), LPCBYTE(in),
  349. ' DWORD(in), LPSCARD_IO_REQUEST(inout), LPBYTE(out), LPDWORD(inout))
  350. Public Declare Function SCardTransmit Lib "winscard.dll" ( _
  351.     ByVal hCard As Long, _
  352.     ByRef pioSendPci As SCARD_IO_REQUEST, _
  353.     ByRef pbSendBuffer As Byte, _
  354.     ByVal cbSendLength As Long, _
  355.     ByRef pioRecvPci As SCARD_IO_REQUEST, _
  356.     ByRef pbRecvBuffer As Byte, _
  357.     ByRef pcbRecvLength As Long _
  358. ) As Long
  359.  
  360. Public Declare Function SCardTransmitLong Lib "winscard.dll" Alias "SCardTransmit" ( _
  361.     ByVal hCard As Long, _
  362.     ByRef pioSendPci As SCARD_IO_REQUEST, _
  363.     ByRef pbSendBuffer As Byte, _
  364.     ByVal cbSendLength As Long, _
  365.     ByVal pioRecvPci As Long, _
  366.     ByRef pbRecvBuffer As Byte, _
  367.     ByRef pcbRecvLength As Long _
  368. ) As Long
  369.  
May 31 '13 #5

Post your reply

Sign in to post your reply or Sign up for a free account.