使用 swift 验证 md5 哈希密码
Verify md5 hash password with swift
我正在尝试从 Blob 中获取 NSData
对象以将其加载到 Web 视图中。我已阅读有关 SQLite.swift 的文档,但我不清楚。请帮我。我想我需要一个工作示例。
我的代码:
https://gist.github.com/gobozgz/9d1b02364f878bc1a026
import UIKit
import SQLite
class AreaInfoViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Here I Will load the webView PDFFile into the webView
// webView.loadRequest(getAreaPdf())
}
func getAreaPdf () -> NSDATA {
var myPdf:NSDATA // I think this is wrong
let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let docsDir = dirPaths[0]
let databasePath = docsDir.stringByAppendingString("/db.sqlite")
let db = try! Connection(databasePath, readonly: true)
let areas = Table("areas")
let id = Expression<Int64>("id")
let name = Expression<String>("name")
let pdffile = Expression<SQLite.Blob>("pdffile")
let query = areas.select(id,name,pdffile)
.filter(id == 1)
.limit(1)
let result = db.prepare(query)
for row in result {
myPdf = row[pdffile] // Obviusly this is wrong
}
return myPdf // Obviusly this is wrong too
}
}
我终于用 bcrypt 代替了 md5。我使用了 JKBCrypt 和 JKBCrypt.verifyPassword
因为我使用的是从 php 生成的哈希存储的密码,所以我不得不使用一些小技巧:
var hash = user[password]
let regex = try! NSRegularExpression(pattern: "\y\\$", options: .CaseInsensitive)
hash = regex.stringByReplacingMatchesInString(hash, options: [], range: NSRange(0..<hash.utf16.count), withTemplate: "\a\\$")
auth = JKBCrypt.verifyPassword(userPassword, matchesHash: hash)!
我正在尝试从 Blob 中获取 NSData
对象以将其加载到 Web 视图中。我已阅读有关 SQLite.swift 的文档,但我不清楚。请帮我。我想我需要一个工作示例。
我的代码: https://gist.github.com/gobozgz/9d1b02364f878bc1a026
import UIKit
import SQLite
class AreaInfoViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Here I Will load the webView PDFFile into the webView
// webView.loadRequest(getAreaPdf())
}
func getAreaPdf () -> NSDATA {
var myPdf:NSDATA // I think this is wrong
let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let docsDir = dirPaths[0]
let databasePath = docsDir.stringByAppendingString("/db.sqlite")
let db = try! Connection(databasePath, readonly: true)
let areas = Table("areas")
let id = Expression<Int64>("id")
let name = Expression<String>("name")
let pdffile = Expression<SQLite.Blob>("pdffile")
let query = areas.select(id,name,pdffile)
.filter(id == 1)
.limit(1)
let result = db.prepare(query)
for row in result {
myPdf = row[pdffile] // Obviusly this is wrong
}
return myPdf // Obviusly this is wrong too
}
}
我终于用 bcrypt 代替了 md5。我使用了 JKBCrypt 和 JKBCrypt.verifyPassword
因为我使用的是从 php 生成的哈希存储的密码,所以我不得不使用一些小技巧:
var hash = user[password]
let regex = try! NSRegularExpression(pattern: "\y\\$", options: .CaseInsensitive)
hash = regex.stringByReplacingMatchesInString(hash, options: [], range: NSRange(0..<hash.utf16.count), withTemplate: "\a\\$")
auth = JKBCrypt.verifyPassword(userPassword, matchesHash: hash)!