Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.80 KB | None | 0 0
  1. Option Explicit
  2. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
  3. Public OK As Boolean
  4. Dim m_Password As String
  5. Dim userpwd As String
  6. Dim usercd As String
  7. Dim useremail As String
  8. Dim usernm As String
  9.  
  10. Private Sub cmdforgetpassword_Click()
  11. Dim cSql As String
  12. Dim Rs As New ADODB.Recordset
  13.  
  14. If txtUserName.Text = "" Then
  15. MsgBox "Please Enter UserName", vbOKOnly, "ProjPRS"
  16. txtUserName.SetFocus
  17. txtUserName.SelStart = 0
  18. txtUserName.SelLength = Len(txtUserName.Text)
  19. Exit Sub
  20. End If
  21.  
  22. cSql = "SELECT USERMAST.*,DEPTMAST.DEPTNM FROM USERMAST,DEPTMAST WHERE (USERMAST.DEPTCD*=DEPTMAST.DEPTCD) AND (USERMAST.USERCD='" & Trim(txtUserName.Text) & "')"
  23. Set Rs = ReturnRecSet(CnnGlobal, adCmdText, cSql)
  24. If (Rs Is Nothing) Then GoTo ErrProc
  25.  
  26. If (Rs.EOF) Then
  27. MsgBox "User code not found in master. Please enter valid user code.", vbCritical, "Invalid Entry!"
  28. txtUserName.SelStart = 0
  29. txtUserName.SelLength = Len(txtUserName.Text)
  30. Exit Sub
  31. End If
  32.  
  33. Dim StrHtml As String
  34. Dim Sendto As String
  35. Dim objrs As New ADODB.Recordset
  36. Dim iCount As Integer
  37. Dim MylistItem As ListItem
  38.  
  39. On Error GoTo ErrProc
  40.  
  41. Dim myout As Outlook.Application
  42. Dim myNS As NameSpace
  43. Dim myInbox As MAPIFolder
  44.  
  45. Set myout = New Outlook.Application
  46. Set myNS = myout.GetNamespace("MAPI")
  47. Set myInbox = myNS.GetDefaultFolder(olFolderInbox)
  48. Dim msReply As MailItem
  49.  
  50. Sendto = ""
  51.  
  52. cSql = " Select usernm,userpwd,useremail from usermast where usercd = '" & Trim(txtUserName) & "' "
  53. objrs.Open cSql, CnnGlobal, adOpenStatic, adLockReadOnly
  54. Do While Not objrs.EOF
  55. Sendto = Sendto & "; " & Trim(objrs.Fields("USEREMAIL").Value & "")
  56. objrs.MoveNext
  57. Loop
  58. objrs.Close
  59. Set objrs = Nothing
  60.  
  61. StrHtml = ""
  62. StrHtml = "<Table align=left cellpadding=10 border=1 width=100%><Caption align=Center><b>Your Permasoft Password :</b></Caption>"
  63. StrHtml = StrHtml + "<td align = center colspan=0 Bgcolor = RGB(102,179,230)><B> User Code </B></td>"
  64. StrHtml = StrHtml + "<td align = center Bgcolor = RGB(102,179,230)><B> Password </B></td>"
  65.  
  66. usercd = Trim(Rs.Fields("usercd").Value)
  67. userpwd = Trim(Rs.Fields("userpwd").Value)
  68. usernm = Trim(Rs.Fields("usernm").Value)
  69.  
  70. StrHtml = StrHtml + "<tr>"
  71. StrHtml = StrHtml + "<td align = center bgcolor = RGB(180,236,243)> " & Trim(usercd) & " </td>"
  72. StrHtml = StrHtml + "<td align = center bgcolor = RGB(180,236,243)> " & Trim(userpwd) & " </td>"
  73.  
  74.  
  75. '' Csql = "select userpwd,useremail from usermast where usercd='" & Trim(txtUserName.Text) & "'"
  76. '' Rs.Open Csql, CnnGlobal, adOpenStatic, adLockReadOnly
  77.  
  78. '' userpwd = Trim(Rs.Fields("userpwd").Value)
  79. '' useremail = Trim(Rs.Fields("useremail").Value)
  80.  
  81.  
  82. '' StrHtml = StrHtml + "<tr>"
  83. '' StrHtml = StrHtml + "<td align = center bgcolor = RGB(180,236,243)> " & Trim("userpwd") & " </td>"
  84.  
  85. StrHtml = StrHtml + "</table>"
  86.  
  87. Set msReply = myInbox.Items.Add
  88.  
  89. ' SendTo = "iterp@prs-permacel.com" 'Remove For Testing
  90. msReply.To = Sendto
  91. ' msReply.CC = CClist
  92. ' msReply.Subject = Trim(Rs.Fields("usernm").Value)
  93. msReply.Subject = "Your Permasoft Password"
  94. msReply.HTMLBody = StrHtml
  95. msReply.Send
  96.  
  97. Set myInbox = Nothing
  98. Set myNS = Nothing
  99. Set myout = Nothing
  100.  
  101. MsgBox "Please check your Inbox", vbOKOnly
  102.  
  103. Exit Sub
  104. ErrProc:
  105. MsgBox "Error in forgetPassword Function : " & Err.Description & " No: " & Err.Number
  106. End Sub
  107.  
  108. Private Sub Form_Load()
  109. Dim sBuffer As String
  110. Dim lSize As Long
  111. If (CheckSingleMode = 0) Then End
  112. OK = False
  113. sBuffer = Space$(255)
  114. lSize = Len(sBuffer)
  115. Call GetUserName(sBuffer, lSize)
  116. If lSize > 0 Then
  117. txtUserName.Text = Left$(sBuffer, lSize)
  118. Else
  119. txtUserName.Text = vbNullString
  120. End If
  121. m_Password = ""
  122.  
  123.  
  124. 'by shailesh 06\07\07
  125.  
  126. txtUserName.Text = Left$(sBuffer, lSize)
  127. txtPassword.Text = ""
  128. m_Password = ""
  129. txtUserName.Text = "ITTECH"
  130. txtPassword.Text = "ITTECH"
  131. End Sub
  132.  
  133. Private Sub CmdCancel_Click()
  134. OK = False
  135. Me.Hide
  136. End Sub
  137.  
  138. Private Sub cmdok_Click()
  139. Dim d As String
  140. If (OK = True) Then
  141. Me.Hide
  142. Dim de As String
  143. 'If g_usercd = "" Then
  144.  
  145. Dim ado As New ADODB.Connection
  146. de = "update usermast set logedin=1 where usercd='" & g_usercd & "'"
  147. CnnGlobal.Execute de
  148. ' Else
  149. ' MsgBox "you are already in login", vbInformation, "Alert"
  150. ' End If
  151. End If
  152. End Sub
  153. Private Sub txtPassword_GotFocus()
  154. SendKeys "{End}"
  155. SendKeys "+{Home}"
  156. End Sub
  157.  
  158. Private Sub txtpassword_Validate(Cancel As Boolean)
  159. Static iLoginTry As Integer
  160. If (Trim(UCase(txtPassword.Text)) = Trim(UCase(m_Password))) Then
  161. OK = True
  162. Cancel = False
  163. g_usercd = Trim(txtUserName.Text)
  164. Else
  165. If (iLoginTry < 2) Then
  166. MsgBox "Invalid Password, try again!", , "Login"
  167. OK = False
  168. txtPassword.SetFocus
  169. txtPassword.SelStart = 0
  170. txtPassword.SelLength = Len(txtPassword.Text)
  171. Cancel = True
  172. iLoginTry = iLoginTry + 1
  173. ElseIf (iLoginTry >= 2) Then
  174. MsgBox "Login failed 3 times. Please try again.", vbCritical, "Access Denied!"
  175. Me.Hide
  176. Exit Sub
  177. End If
  178. End If
  179. End Sub
  180.  
  181. Private Sub txtUserName_GotFocus()
  182. SendKeys "{End}"
  183. SendKeys "+{Home}"
  184. End Sub
  185.  
  186. Private Sub txtUserName_Validate(Cancel As Boolean)
  187. If (Len(Trim(txtUserName.Text)) < 1) Then
  188. MsgBox "User name must be entered.", vbInformation, "Null Entry!"
  189. Cancel = True
  190. Exit Sub
  191. End If
  192.  
  193. Dim objrs As New ADODB.Recordset
  194. Dim cSql As String
  195.  
  196. cSql = "SELECT USERMAST.*,DEPTMAST.DEPTNM FROM USERMAST,DEPTMAST WHERE (USERMAST.DEPTCD*=DEPTMAST.DEPTCD) AND (USERMAST.USERCD='" & Trim(txtUserName.Text) & "')"
  197. Set objrs = ReturnRecSet(CnnGlobal, adCmdText, cSql)
  198. If (objrs Is Nothing) Then GoTo ErrProc
  199.  
  200. If (objrs.EOF) Then
  201. MsgBox "User code not found in master. Please enter valid user code.", vbCritical, "Invalid Entry!"
  202. txtUserName.SelStart = 0
  203. txtUserName.SelLength = Len(txtUserName.Text)
  204. Cancel = True
  205. Exit Sub
  206. End If
  207. If (Not objrs.EOF) Then
  208. m_Password = ""
  209. m_Password = Trim(objrs.Fields("UserPwd").Value & "")
  210. With g_User
  211. .location = Trim(objrs.Fields("LOCATIONCD").Value & "")
  212. .USERCODE = Trim(objrs.Fields("UserCd").Value & "")
  213. .UserName = Trim(objrs.Fields("UserNM").Value & "")
  214. .UserType = Trim(objrs.Fields("UserType").Value & "")
  215. .deptcd = Trim(objrs.Fields("deptcd").Value & "")
  216. .deptnm = Trim(objrs.Fields("deptNM").Value & "")
  217. g_UserDeptcd = Trim(objrs.Fields("deptcd").Value & "")
  218. g_UserLocation = Trim(objrs.Fields("LOCATIONCD").Value & "")
  219. g_UserDeptHead = Trim(objrs.Fields("deptHEAD").Value & "")
  220.  
  221. If (FillUserMenuAccess = 0) Then
  222. MsgBox "Cant login into system.", vbCritical, "Unexpected Eror!"
  223. Cancel = True
  224. Exit Sub
  225. End If
  226. End With
  227. End If
  228. Exit Sub
  229.  
  230. ErrProc:
  231. Cancel = True
  232. MsgBox "Error in txtUserName_Validate procedure." & Trim(Err.Number) & " Desc: " & Trim(Err.Description)
  233. End Sub
  234.  
  235.  
  236. Private Function FillUserMenuAccess() As Integer
  237. Dim objrs As New ADODB.Recordset
  238. Dim cSql As String
  239. Dim iCount As Integer
  240.  
  241. cSql = "SELECT * FROM USER_MENUMAST WHERE (USERCD='" & Trim(txtUserName.Text) & "') AND (GRANTED=1) ORDER BY MENUCD"
  242. Set objrs = ReturnRecSet(CnnGlobal, adCmdText, cSql)
  243. If (objrs Is Nothing) Then GoTo ErrProc
  244. If (objrs.EOF) Then
  245. MsgBox "No profile set for the specified user. Contact Administrator for details.", vbCritical, "Invalid Entry!"
  246. txtUserName.SelStart = 0
  247. txtUserName.SelLength = Len(txtUserName.Text)
  248. If txtUserName.Enabled Then txtUserName.SetFocus
  249. FillUserMenuAccess = 0
  250. Exit Function
  251. End If
  252.  
  253. iCount = 0
  254. objrs.MoveFirst
  255. Do While Not (objrs.EOF)
  256. With g_User
  257. .MenuAccess(iCount) = Trim(objrs.Fields("MENUCD").Value & "")
  258. End With
  259. iCount = iCount + 1
  260. objrs.MoveNext
  261. Loop
  262.  
  263. FillUserMenuAccess = 1
  264. Exit Function
  265. ErrProc:
  266. FillUserMenuAccess = 0
  267. MsgBox "Error in txtUserName_Validate procedure." & Trim(Err.Number) & " Desc: " & Trim(Err.Description)
  268. End Function
  269.  
  270. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  271. If Not (Me.ActiveControl Is Nothing) Then
  272. ControlNavigate Me.ActiveControl, KeyCode
  273. End If
  274. If (KeyCode = vbKeyEscape) Then
  275. Call CmdCancel_Click
  276. End If
  277. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement