QT下的base的加密

Qt之QCustomPlot(图形库)
//加密,保存password
QString password = ui->pswLineEdit->text().trimmed();
QByteArray passArray = password.toAscii();
QSqlQuery query;
query.prepare(QString(“insert into User(username, password, cardno, usertype) values (:username, :password, :cardno, :usertype)”));
query.addBindValue(userName);
query.addBindValue(passArray.toBase64());
query.addBindValue(cardNo);
query.addBindValue(0);
if(query.exec())
{
//succeed
}

//解密,验证登陆  
QString password = ui->pswLineEdit->text().trimmed();  
QSqlQuery query;  
query.exec(QString("select password from User where username = '%1'").arg(username));  
if(!query.isActive())  
{  
    //查询数据库错误  
}  
if(!query.next())  
{  
    //用户名不存在  
}  
else  
{  
    QString dataPassword = query.value(0).toString();  
    //decrypt  
    QByteArray tempArray = QByteArray::fromBase64(dataPassword.toAscii());  
    if(password != QString(tempArray))  
    //...  
}  

你可能感兴趣的:(C++)