Angepinnt Kleine-Scripting-Fragen

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    • Bekomme leider diesen fehlermeldung: MODULE: Unable to load x64/modules/ml_bcrypt_64.so (liblua5.1.so.5.1: cannot open shared object file: No such file or directory)
      Habe versucht die Liblua5.1.so zu installieren nur dabei bekomme ich auch einen fehler angezeigt.
      [IMG:http://www.speedtest.net/result/5426322119.png]
      Die deutsche Sprache ist Freeware.
      Das heißt, du darfst sie uneingeschränkt nutzen. ABER(!) die deutsche Sprache ist NICHT Open Source.
      Das heißt, du darfst sie nicht nach deinen Vorstellungen verändern!

      Ein Problem ist halb gelöst, wenn es klar formuliert ist.
    • Du könntest allerdings noch probieren, in dem Script einfach die Funktion, die dir den Salt generiert, zu ändern, so dass diese den entsprechenden Prefix "$2y$" hat.

      LUA-Quellcode

      1. function Cwbbc:getRandomSalt()
      2. local salt = "$2y$08$"
      3. for i = 1, 22 do
      4. local rnd = math.random(1, #blowfishCharacters)
      5. salt = ("%s%s"):format(salt, blowfishCharacters:sub(rnd, rnd))
      6. end
      7. self:debugOutput({randomSalt = salt, saltLength = #salt})
      8. return salt
      9. end
      Alles anzeigen
      DEAL WITH IT.

      github.com/DKongHD
      Altes OOP UI-Framework: github.com/DKongHD/MTA-Framework-OOP
    • DKong schrieb:

      Du könntest allerdings noch probieren, in dem Script einfach die Funktion, die dir den Salt generiert, zu ändern, so dass diese den entsprechenden Prefix "$2y$" hat.
      Probiere es mal aus.

      Edit: prntscr.com/jud1hv
      Also ich weiß nicht mehr was ich probieren könnte bin seit tagen drann :D.

      LUA-Quellcode

      1. --
      2. -- HorrorClown (PewX)
      3. -- Using: IntelliJ IDEA 14 Ultimate
      4. -- Date: 24.11.2014 - Time: 03:54
      5. -- License: MIT/X11
      6. -- pewx.de // iGaming-mta.de // iRace-mta.de // iSurvival.de // mtasa.de
      7. --
      8. --Contributors:
      9. -- Launemax <www.launemax.at>
      10. --
      11. Cwbbc = {}
      12. function Cwbbc:constructor(sHost, sUser, sPass, sDBName, sPort, bDebug)
      13. self.sHost = sHost
      14. self.sUser = sUser
      15. self.sDBName = sDBName
      16. self.debug = bDebug or false
      17. self.hCon = dbConnect("mysql", ("dbname=%s;host=%s;port=%s"):format(sDBName, sHost, sPort), sUser, sPass, "autoreconnect=1")
      18. if self.hCon then
      19. self:query("SET NAMES utf8;")
      20. self:message("Successfully connected!")
      21. if self.debug then self:debugOutput({Warning = "Debug mode is enabled. Sensitive data (eg passwords) are displayed!"}) end
      22. else
      23. self:message("Can't connect to mysql server!")
      24. stopResource(getThisResource())
      25. end
      26. end
      27. function bcrypt_digest(password, pwSalt)
      28. return passwordHash(password, "bcrypt", {salt=pwSalt})
      29. end
      30. function Cwbbc:destructor()
      31. self.sHost = nil
      32. self.sUser = nil
      33. self.sDBName = nil
      34. destroyElement(self.hCon)
      35. end
      36. --[[
      37. --//
      38. --|| Woltlab Community Framework
      39. --\\
      40. ]]
      41. function Cwbbc:register(sUsername, sPW, sEmail, nGroupID, nRankID, nLanguageID)
      42. if not self.hCon then self:message("Not connected to mysql server") return false end
      43. assert(type(sUsername) == "string", "Invalid string @ argument 1")
      44. assert(type(sPW) == "string", "Invalid string @ argument 2")
      45. assert(type(sEmail) == "string", "Invalid string @ argument 3")
      46. assert(nGroupID == nil or type(nGroupID) == "number", "Invalid number @ argument 4")
      47. assert(nRankID == nil or type(nRankID) == "number", "Invalid number @ argument 5")
      48. assert(nLanguageID == nil or type(nLanguageID) == "number", "Invalid number @ argument 6")
      49. if nGroupID == nil then nGroupID = 2 end
      50. if nRankID == nil then nRankID = 2 end
      51. if nLanguageID == nil then nLanguageID = 1 end
      52. local nTimestamp = getRealTime().timestamp
      53. --If UserID is available, the username is already in use
      54. if self:getUserID(sUsername) then
      55. return false
      56. end
      57. local pwHash = self:getDoubleSaltedHash(sPW)
      58. self:debugOutput({pwHash = pwHash, isBlowfish = self:isBlowfish(pwHash)})
      59. self:query("START TRANSACTION;")
      60. local result, _, userID = self:query("INSERT INTO wcf1_user(`username`,`email`,`password`,`languageID`,`registrationDate`, `lastActivityTime`,`rankID`,`userOnlineGroupID`) VALUES (?,?,?,?,?,?,?,?);", sUsername, sEmail, pwHash, nLanguageID, nTimestamp, nTimestamp, nRankID, nGroupID)
      61. if result ~= false then
      62. local result = self:query("SELECT `optionID`,`defaultValue` FROM wcf1_user_option;")
      63. if result ~= false then
      64. local columns = {}
      65. local values = {}
      66. for _, row in ipairs(result) do
      67. table.insert(columns, "userOption"..row["optionID"])
      68. local v = row["defaultValue"]
      69. if v == false then v = "" else v = tostring(v) end
      70. table.insert(values, v)
      71. end
      72. local result = self:query("INSERT INTO wcf1_user_option_value(`userID`, `"..table.concat(columns, "`,`").."`) VALUES (?, '"..table.concat(values, "','").."');", userID)
      73. if result ~= false then
      74. local result = self:query("INSERT INTO wcf1_user_to_group(`userID`,`groupID`) VALUES (?,?);", userID, nGroupID)
      75. if result ~= false then
      76. local result = self:query("INSERT INTO wcf1_user_to_language(`userID`,`languageID`) VALUES (?,?);", userID, nLanguageID)
      77. if result ~= false then
      78. self:query("COMMIT;")
      79. return true, userID
      80. end
      81. end
      82. end
      83. end
      84. end
      85. self:query("ROLLBACK;")
      86. return false
      87. end
      88. function Cwbbc:login(sUsername, sPW) return self:comparePassword(sUsername, sPW) end
      89. function Cwbbc:comparePassword(sUsername, sPW)
      90. if not self.hCon then self:message("Not connected to mysql server") return false end
      91. assert(type(sUsername) == "string", "Invalid string @ argument 1")
      92. assert(type(sPW) == "string", "Invalid string @ argument 2")
      93. if self:get("wcf1_user", "username", "username", sUsername) then
      94. local dbHash = self:get("wcf1_user", "password", "username", sUsername)
      95. local salt = string.sub(dbHash, 1, 29)
      96. local pwHash = self:getDoubleSaltedHash(sPW, salt)
      97. self:debugOutput({dbHash = dbHash, salt = salt, pwHash = pwHash})
      98. self:message("test")
      99. return (dbHash == pwHash)
      100. end
      101. return false
      102. end
      103. function Cwbbc:getUserID(sUsername, bMail)
      104. if not self.hCon then self:message("Not connected to mysql server!") return false end
      105. assert(type(sUsername) == "string", "Invalid string @ argument 1")
      106. local qResult = bMail and self:get("wcf1_user", "userID", "email", sUsername) or self:get("wcf1_user", "userID", "username", sUsername)
      107. if qResult ~= nil then return tonumber(qResult) else return false end
      108. end
      109. function Cwbbc:getUserName(nUID)
      110. if not self.hCon then self:message("Not connected to mysql server!") return false end
      111. assert((type(nUID) == "number"), "Invalid number @ argument 1")
      112. return self:get("wcf1_user", "username", "userID", nUID) or false
      113. end
      114. function Cwbbc:getUserMail(nUID)
      115. if not self.hCon then self:message("Not connected to mysql server!") return false end
      116. assert((type(nUID) == "number"), "Invalid number @ argument 1")
      117. return self:get("wcf1_user", "email", "userID", nUID) or false
      118. end
      119. function Cwbbc:getUserTitle(nUID)
      120. if not self.hCon then self:message("Not connected to mysql server") return false end
      121. assert(type(nUID) == "number", "Invalid number @ argument 1")
      122. return self:get("wcf1_user", "userTitle", "userID", nUID)
      123. end
      124. function Cwbbc:getUserProfil(nUID)
      125. if not self.hCon then self:message("Not connected to mysql server") return false end
      126. assert(type(nUID) == "number", "Invalid number @ argument 1")
      127. return self:get("wcf1_user_avatar", "avatarName", "userID", nUID)
      128. end
      129. function Cwbbc:setUserTitle(nUID, sTitle)
      130. if not self.hCon then self:message("Not connected to mysql server") return false end
      131. assert(type(nUID) == "number", "Invalid number @ argument 1")
      132. assert(type(sTitle) == "string", "Invalid string @ argument 2")
      133. return self:set("wcf1_user", "userTitle", sTitle, "userID", nUID)
      134. end
      135. function Cwbbc:isUserActivated(nUID)
      136. if not self.hCon then self:message("Not connected to mysql server") return false end
      137. assert(type(nUID) == "number", "Invalid number @ argument 1")
      138. return (self:get("wcf1_user", "activationCode", "userID", nUID) == 0)
      139. end
      140. function Cwbbc:getUserLanguageID(nUID)
      141. if not self.hCon then self:message("Not connected to mysql server") return false end
      142. assert(type(nUID) == "number", "Invalid number @ argument 1")
      143. return tonumber(self:get("wcf1_user", "languageID", "userID", nUID))
      144. end
      145. function Cwbbc:setUserLanguageID(nUID, nLanguageID)
      146. if not self.hCon then self:message("Not connected to mysql server") return false end
      147. assert(type(nUID) == "number", "Invalid number @ argument 1")
      148. assert(type(nLanguageID) == "number", "Invalid number @ argument 2")
      149. return self:set("wcf1_user", "languageID", nLanguageID, "userID", nUID)
      150. end
      151. function Cwbbc:getLanguageItemText(sLanguageItem, nLanguageID)
      152. if not self.hCon then self:message("Not connected to mysql server") return false end
      153. assert(type(sLanguageItem) == "string", "Invalid string @ argument 1")
      154. assert(type(nLanguageID) == "number", "Invalid number @ argument 2")
      155. return self:get("wcf1_language_item", "languageItemValue", "languageItem", sLanguageItem, "languageID", nLanguageID) or false
      156. end
      157. function Cwbbc:getUserStorage(nUID, sField)
      158. if not self.hCon then self:message("Not connected to mysql server") return false end
      159. assert(type(nUID) == "number", "Invalid number @ argument 1")
      160. assert(type(sField) == "string", "Invalid string @ argument 2")
      161. local result = self:query(("SELECT * FROM wcf1_user_storage WHERE userID = '%s' AND field = '%s'"):format(nUID, sField))
      162. if result and result[1] then return result[1].fieldValue end
      163. return false
      164. end
      165. --[[
      166. --//
      167. --|| Woltlab Burning Board
      168. --\\
      169. ]]
      170. function Cwbbc:getBoardTitle(nBoardID)
      171. if not self.hCon then self:message("Not connected to mysql server") return false end
      172. assert(type(nBoardID) == "number", "Invalid number @ argument 1")
      173. return self:get("wbb1_board", "title", "boardID", nBoardID) or false
      174. end
      175. function Cwbbc:getBoardID(sTitle, nBoardType)
      176. if not self.hCon then self:message("Not connected to mysql server") return false end
      177. assert(type(sTitle) == "string", "Invalid string @ argument 1")
      178. assert(type(nBoardType) == "number", "Invalid number @ argument 2")
      179. return tonumber(mysql.get("wbb1_board", "boardID", "title", sTitle, "boardType", nBoardType))
      180. end
      181. function Cwbbc:addThread(nUID, nBoardID, sTitle, sText)
      182. if not self.hCon then self:message("Not connected to mysql server") return false end
      183. assert(type(nUID) == "number", "Invalid number @ argument 1")
      184. assert(type(nBoardID) == "number", "Invalid number @ argument 2")
      185. assert(type(sTitle) == "string", "Invalid string @ argument 3")
      186. assert(type(sText) == "string", "Invalid string @ argument 4")
      187. local username = self:getUserName(nUID)
      188. local timestamp = getRealTime().timestamp
      189. local result, _, threadID = self:query("INSERT INTO wbb1_thread (boardID, topic, userID, lastPosterID, username, lastPoster, time, lastPostTime) VALUES (?,?,?,?,?,?,?,?)", nBoardID, sTitle, nUID, nUID, username, username, timestamp, timestamp)
      190. if result then
      191. local result, _, postID = self:query("INSERT INTO wbb1_post (threadID, userID, username, subject, message, time) VALUES (?,?,?,?,?,?)", threadID, nUID, username, sTitle, sText, timestamp)
      192. if result then
      193. self:set("wbb1_thread", "firstPostID", postID, "threadID", threadID)
      194. self:set("wbb1_thread", "lastPostID", postID, "threadID", threadID)
      195. return threadID
      196. end
      197. end
      198. end
      199. function Cwbbc:addPost(nUID, nThreadID, sSubject, sText)
      200. if not self.hCon then self:message("Not connected to mysql server") return false end
      201. assert(type(nUID) == "number", "Invalid number @ argument 1")
      202. assert(type(nThreadID) == "number", "Invalid number @ argument 2")
      203. assert(type(sSubject) == "string", "Invalid string @ argument 3")
      204. assert(type(sText) == "string", "Invalid string @ argument 4")
      205. local username = self:getUserName(nUID)
      206. local timestamp = getRealTime().timestamp
      207. local result, _, postID = self:query("INSERT INTO wbb1_post (threadID, userID, username, subject, message, time) VALUES (?,?,?,?,?,?)", nThreadID, nUID, username, sSubject, sText, timestamp)
      208. if result then
      209. local replies = tonumber(self:get("wbb1_thread", "replies", "threadID", nThreadID))
      210. return (self:set("wbb1_thread", "lastPostID", postID, "threadID", nThreadID) and self:set("wbb1_thread", "lastPostTime", timestamp, "threadID", nThreadID) and self:set("wbb1_thread", "replies", replies + 1, "threadID", nThreadID)) or false
      211. end
      212. end
      213. --[[
      214. --//
      215. --|| Hashing functions for Waltlab Community Framework
      216. --\\
      217. ]]
      218. --Returns true if given hash looks like a valid bcrypt hash
      219. --Refrence: https://github.com/WoltLab/WCF/blob/master/wcfsetup/install/files/lib/util/PasswordUtil.class.php#L92
      220. function Cwbbc:isBlowfish(sHash)
      221. --Blowfish hashing with a salt as follows: "$2a$", "$2x$" or "$2y$", a two digit cost parameter | Source: http://php.net/manual/en/function.crypt.php
      222. return sHash:find("%$2[axy]%$%d%d%$") and true or false
      223. end
      224. --Returns a double salted bcrypt hash
      225. --Refrence: https://github.com/WoltLab/WCF/blob/master/wcfsetup/install/files/lib/util/PasswordUtil.class.php#L174
      226. function Cwbbc:getDoubleSaltedHash(sPassword, sSalt)
      227. if sSalt == nil then
      228. sSalt = self:getRandomSalt()
      229. end
      230. local doubleSaltedHash = self:getSaltedHash(self:getSaltedHash(sPassword, sSalt), sSalt)
      231. return string.sub(doubleSaltedHash, 1, 60)
      232. end
      233. --Returns a simple salted bcrypt hash
      234. --Reference: https://github.com/WoltLab/WCF/blob/master/wcfsetup/install/files/lib/util/PasswordUtil.class.php#L189
      235. function Cwbbc:getSaltedHash(sPassword, sSalt)
      236. if sSalt == nil then
      237. sSalt = self:getRandomSalt()
      238. end
      239. return bcrypt_digest(sPassword, sSalt)
      240. end
      241. --Returns a random blowfish compatible salt
      242. --Reference: https://github.com/WoltLab/WCF/blob/master/wcfsetup/install/files/lib/util/PasswordUtil.class.php#L202
      243. local blowfishCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./"
      244. function Cwbbc:getRandomSalt()
      245. local salt = "$2a$08$"
      246. for i = 1, 22 do
      247. local rnd = math.random(1, #blowfishCharacters)
      248. salt = ("%s%s"):format(salt, blowfishCharacters:sub(rnd, rnd))
      249. end
      250. self:debugOutput({randomSalt = salt, saltLength = #salt})
      251. return salt
      252. end
      253. --[[
      254. --//
      255. --|| Useful methods
      256. --\\
      257. ]]
      258. function Cwbbc:message(sMessage)
      259. outputServerLog(("[%[email protected]%s]: %s"):format(self.sUser, self.sDBName, sMessage))
      260. end
      261. function Cwbbc:debugOutput(tMessages)
      262. if not self.debug then return end
      263. for sIndicator, sMessage in pairs(tMessages) do
      264. outputServerLog(("[iConnect][%s] %s"):format(tostring(sIndicator), tostring(sMessage)))
      265. outputConsole(("[iConnect][%s] %s"):format(tostring(sIndicator), tostring(sMessage)))
      266. end
      267. end
      268. --[[
      269. --//
      270. --|| Database methods (outdated, but still works)
      271. --\\
      272. ]]
      273. function Cwbbc:query(q, ...)
      274. local query = dbQuery(self.hCon, q, ...)
      275. local result, qRows, qliID = dbPoll(query, 200)
      276. if result == false then
      277. return false
      278. elseif result then
      279. return result, qRows, qliID
      280. else dbFree(query) end
      281. end
      282. function Cwbbc:insert(t, c, v, ...) --t = table | c = columns | v = values
      283. return dbExec(self.hCon, ("INSERT INTO %s (%s) VALUES (%s)"):format(t, c, v), ...)
      284. end
      285. function Cwbbc:set(t, c, cV, w, wV, wO, wVO) --t = table | c = column | cV = columnValue | w = where | wV = whereValue | wO = whereOptional | wVO = whereValueOptional
      286. if wO ~= nil then
      287. return dbExec(self.hCon, "UPDATE ?? SET ??=? WHERE ??=? AND ??=?", t, c, cV, w, wV, wO, wVO)
      288. else
      289. return dbExec(self.hCon, "UPDATE ?? SET ??=? WHERE ??=?", t, c, cV, w, wV)
      290. end
      291. end
      292. function Cwbbc:get(t, c, w, wV, wO, wVO) --t = table | c = column | w = where | wV = whereValue | wO = whereOptional | wVO = whereValueOptional
      293. local q, rs
      294. if wO and wVO then q, rs = self:query(("SELECT %s FROM %s WHERE %s = '%s' AND %s = '%s'"):format(c, t, w, wV, wO, wVO)) elseif w and wV then q, rs = self:query(("SELECT %s FROM %s WHERE %s = '%s'"):format(c, t, w, wV)) else q, rs = self:query(("SELECT %s FROM %s"):format(c, t)) end
      295. if not q then return false end
      296. if rs > 1 then return q end
      297. for _, row in ipairs(q) do
      298. return row[c]
      299. end
      300. end
      301. --[[
      302. --//
      303. --|| Other informations on resource startup
      304. --\\
      305. ]]
      306. addEventHandler("onResourceStart", resourceRoot,
      307. function()
      308. if type(bcrypt_digest) ~= "function" then
      309. outputServerLog("[iConnect] bcrypt module required to use login and register methods!")
      310. end
      311. if type(unserialize) ~= "function" or type(serialize) ~= "function" then
      312. outputServerLog("[iConnect] unserialize/serialize function required to use conversation methods!")
      313. end
      314. end
      315. )
      Alles anzeigen
      [IMG:http://www.speedtest.net/result/5426322119.png]
      Die deutsche Sprache ist Freeware.
      Das heißt, du darfst sie uneingeschränkt nutzen. ABER(!) die deutsche Sprache ist NICHT Open Source.
      Das heißt, du darfst sie nicht nach deinen Vorstellungen verändern!

      Ein Problem ist halb gelöst, wenn es klar formuliert ist.

      Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von iLimix ()

    • LUA-Quellcode

      1. function Cwbbc:getRandomSalt()
      2. local salt = ""
      3. for i = 1, 22 do
      4. local rnd = math.random(1, #blowfishCharacters)
      5. salt = ("%s%s"):format(salt, blowfishCharacters:sub(rnd, rnd))
      6. end
      7. self:debugOutput({randomSalt = salt, saltLength = #salt})
      8. return salt
      9. end
      Hab den Fehler jetzt gefunden.
      Du darfst bei der Verwendung von passwordHash keinen Prefix für den Salt haben, dann funktioniert es problemlos.

      Teste das nochmal mit meiner bcrypt Funktion bitte.
      DEAL WITH IT.

      github.com/DKongHD
      Altes OOP UI-Framework: github.com/DKongHD/MTA-Framework-OOP