【WEEK6】 【DAY7】MD5 Encryption Transactions【English Version】

2024.4.7 Sunday
Following the previous article 【WEEK6】 【DAY3】MySQL Functions【English Version】

Contents

    • 5.3. MD5 Encryption
      • 5.3.1. Introduction
      • 5.3.2. Testing MD5 Encryption
        • 5.3.2.1. Plain Text Passwords
        • 5.3.2.2. Implementing Data Encryption
        • 5.3.2.3. Encryption for ID 1
        • 5.3.2.4. Encrypt All Passwords
        • 5.3.2.5. Encryption Upon Insertion
        • 5.3.2.6. Verifying Encrypted Statements
    • 5.4. Summary
  • 6. Transactions and Indexes
    • 6.1. What is a Transaction
    • 6.2. The ACID Principles of Transactions
      • 6.2.1. Atomicity
      • 6.2.2. Consistency: Eventual Consistency (Conservation of Energy)
      • 6.2.3. Isolation
      • 6.2.4.Durability
      • 6.2.5. Problems Caused by Isolation
    • 6.3. Basic Syntax
    • 6.4. Simulated Scenario
      • 6.4.1. Create Table, Insert Data
      • 6.4.2. Simulate Transfer

5.3. MD5 Encryption

5.3.1. Introduction

MD5, standing for Message-Digest Algorithm 5, is used to ensure information transmission is complete and consistent. It is one of the widely used cryptographic hash functions in computing (also known as digest algorithms or hash algorithms), with mainstream programming languages commonly having MD5 implementations. It operates data (such as Chinese characters) to another fixed-length value, which is the basic principle of hash functions. MD5 has predecessors including MD2, MD3, and MD4.
Irreversible.

5.3.2. Testing MD5 Encryption

(Create a table first)

-- MD5 --
-- Testing MD5 Encryption
CREATE TABLE `testmd5`(`id` INT(4) NOT NULL,`name` VARCHAR(20) NOT NULL,`pwd` VARCHAR(50) NOT NULL,PRIMARY KEY(`id`)
)ENGINE = INNODB DEFAULT CHARSET = utf8

Insert image description here

5.3.2.1. Plain Text Passwords
-- Plain Text Passwords
INSERT INTO testmd5 VALUES (1, 'ZHANGSAN', '123456'),(2, 'LISI', '123456'),(3, 'WANGWU', '123456')

Insert image description here

5.3.2.2. Implementing Data Encryption
5.3.2.3. Encryption for ID 1
-- Encryption
UPDATE testmd5 SET pwd = MD5(pwd) WHERE id = 1

Insert image description here

5.3.2.4. Encrypt All Passwords
-- Encrypt All Passwords
UPDATE testmd5 SET pwd = MD5(pwd)

Insert image description here

5.3.2.5. Encryption Upon Insertion
-- Encryption Upon Insertion
INSERT INTO testmd5 VALUES (4, 'xiaoming', MD5('123456'))

Insert image description here

5.3.2.6. Verifying Encrypted Statements
-- How to verify: Encrypt the password provided by the user with MD5, then compare it with the encrypted value (when the same value is encrypted the same number of times, the resulting encryption result is exactly the same)
SELECT * FROM testmd5 WHERE `name` = 'xiaoming' AND pwd = MD5('123456')

Insert image description here

5.4. Summary

Insert image description here

 -- ================ Built-in Functions ================-- Numeric Functionsabs(x)            -- Absolute value abs(-10.9) = 10format(x, d)    -- Format number with thousand separator format(1234567.456, 2) = 1,234,567.46ceil(x)            -- Round up ceil(10.1) = 11floor(x)        -- Round down floor(10.1) = 10round(x)        -- Round to the nearest integermod(m, n)        -- m%n m mod n Remainder 10%3=1pi()            -- Get pipow(m, n)        -- m^nsqrt(x)            -- Square rootrand()            -- Random numbertruncate(x, d)    -- Truncate to d decimal places-- Date and Time Functionsnow(), current_timestamp();     -- Current date and timecurrent_date();                    -- Current datecurrent_time();                    -- Current timedate('yyyy-mm-dd hh:ii:ss');    -- Get the date parttime('yyyy-mm-dd hh:ii:ss');    -- Get the time partdate_format('yyyy-mm-dd hh:ii:ss', '%d %y %a %d %m %b %j');    -- Format dateunix_timestamp();                -- Get Unix timestampfrom_unixtime();                -- Convert timestamp to date-- String Functionslength(string)            -- Length of string in byteschar_length(string)        -- Number of characters in stringsubstring(str, position [,length])        -- Substring of str starting at position for length charactersreplace(str, search_str, replace_str)    -- Replace search_str with replace_str in strinstr(string, substring)    -- Position of the first occurrence of substring in stringconcat(string [,...])    -- Concatenate stringscharset(str)            -- Character set of stringlcase(string)            -- Convert to lowercaseleft(string, length)    -- Take length characters from the left of stringload_file(file_name)    -- Load content from a filelocate(substring, string [,start_position])    -- Similar to instr, but can specify start positionlpad(string, length, pad)    -- Pad string on the left with pad until length is reachedltrim(string)            -- Trim leading spacesrepeat(string, count)    -- Repeat string count timesrpad(string, length, pad)    -- Pad string on the right with pad until length is reachedrtrim(string)            -- Trim trailing spacesstrcmp(string1, string2)    -- Compare two strings character by character-- Aggregate Functionscount()sum();max();min();avg();group_concat()-- Other Common Functionsmd5();default();

6. Transactions and Indexes

6.1. What is a Transaction

6.1.1. A transaction is a group of SQL statements that are executed together.
6.1.2. If one SQL statement within the group fails, all SQL statements in that batch are cancelled.
6.1.3. MySQL transaction processing only supports the InnoDB and BDB table types.

6.2. The ACID Principles of Transactions

https://www.jianshu.com/p/133d8b798271

6.2.1. Atomicity

All operations within the entire transaction either complete fully or are completely undone. They do not stop at any intermediate point. If an error occurs during the execution of the transaction, it will be rolled back to the state before the transaction started, as if the transaction had never been executed.

6.2.2. Consistency: Eventual Consistency (Conservation of Energy)

A transaction can encapsulate state changes (unless it is read-only). The system must always remain consistent, no matter how many concurrent transactions there are at any given time. That is, even if there are multiple concurrent transactions, the system must operate as if transactions were serial. Its main features are protectiveness and invariance, using the transfer example, assume there are five accounts, each with a balance of 100 units, then the total of the five accounts is 500 units. If multiple transfers occur among these 5 accounts at the same time, no matter how many concurrent ones, for example, transferring 5 units between A and B, 10 units between C and D, and 15 units between B and E, the total of the five accounts should still be 500 units. This is protectiveness and invariance.

6.2.3. Isolation

Execute transactions in isolation, making them appear as the only operation in the system at a given time. If there are two transactions, running at the same time, performing the same functions, the isolation of the transactions ensures that each transaction is considered by the system to be the only one using the system. This property is sometimes referred to as serializability. To prevent confusion between transaction operations, requests must be serialized or sequenced so that only one request is made on the same data at the same time.

6.2.4.Durability

After the transaction is completed (committed), the changes made by the transaction to the database are permanently saved in the database and will not be rolled back.

6.2.5. Problems Caused by Isolation

Dirty read: Reading uncommitted data from another transaction.
Non-repeatable reads: Reading a row of data from a table and getting different results at different times within a transaction. (This is not necessarily wrong, just inappropriate in some cases)
Phantom reads: Reading data inserted by another transaction within a transaction, leading to inconsistency in the total amount read before and after. (Usually row-affected, e.g., an additional row)

6.3. Basic Syntax

-- Transactions --
-- MySQL transactions are set to auto-commit by default
SET autocommit = 0	-- Disable
SET autocommit = 1	-- Enable (default)-- Manually handling transactions (first, disable auto-commit)
SET autocommit = 0-- Start of transaction
START TRANSACTION	-- Marks the start of a transaction, from this line forward all SQL are in the same transaction
INSERT XX
INSERT XX-- (If successful) commit: persist changes
COMMIT-- (If unsuccessful) rollback: revert to original state
ROLLBACK-- End of transaction (then re-enable auto-commit)
SET autocommit = 1-- Savepoints
SAVEPOINT savepoint_name	-- Sets a savepoint within a transaction
ROLLBACK TO SAVEPOINT savepoint_name	-- Offers a chance to rollback to a previous savepoint
RELEASE SAVEPOINT savepoint_name	-- Removes a savepoint

Insert image description here

6.4. Simulated Scenario

/*
Class test questionA purchases a product priced at 500 units online, paying via bank transfer.
A's bank card balance is 2000, then pays 500 to merchant B.
Merchant B's initial bank card balance is 10000Create shop database and account table and insert 2 records
*/

6.4.1. Create Table, Insert Data

#Simulated scenario
-- Transferring funds
CREATE DATABASE shop CHARACTER SET utf8 COLLATE utf8_general_ci
USE shopCREATE TABLE `account`(`id` INT(3) NOT NULL AUTO_INCREMENT,`name` VARCHAR(30) NOT NULL,`money` DECIMAL(9,2) NOT NULL,PRIMARY KEY (`id`)
)ENGINE = INNODB DEFAULT CHARSET = utf8-- Initialize (insert) relevant data
INSERT INTO account(`name`, `money`)
VALUES ('A', 2000.00),('B', 1000.00)

6.4.2. Simulate Transfer

-- Simulating transfer: Transactions (execute in batches separated by blank lines)
SET autocommit = 0;	-- Disable auto-commitSTART TRANSACTION	-- Start a transactionUPDATE account SET money = money-500 WHERE `name` = 'A';	-- A subtracts 500
UPDATE account SET money = money+500 WHERE `name` = 'B';	-- B adds 500COMMIT;	-- Commit transaction
ROLLBACK;	-- Rollback (only successful before 'commit transaction' is executed)SET autocommit = 1; -- Reset to default

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/300818.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

实景三维在文化旅游领域的应用

实景三维技术,作为一种前沿的科技手段,近年来在文化旅游领域的应用逐渐崭露头角。它能够将真实世界的场景以三维的形式精确呈现,为游客带来身临其境的体验,为文化旅游注入新的活力。本文将探讨实景三维在文化旅游领域的应用及其所…

npm版本切换工具nvm

有了nvm,可以在一台机器上同时安装多个版本的nodejs,然后指定使用某个版本。 前端开发的时候,安装依赖一直是个令我头痛的问题。总是报错,或者不是少了这样就是少了那样,鸡飞狗走。以往,一般要装个enpm&am…

【java的本地锁到分布式锁介绍】

文章目录 1.java本地自带锁介绍及应用synchronized(1)synchronized原理和优化(2)synchronized作用(3)synchronized的使用 CAS(1) CAS原理(2)CAS和synchronized优缺点 lock 2.分布式锁…

基于Spring Boot的网上书城系统(带文档)

主要功能 本次设计任务是要设计一个网上书城管理系统,通过这个系统能够满足网上书城的管理及用户的图书信息管理及购物功能。系统的主要功能包括:首页、个人中心、用户管理、图书类型管理、图书分类管理、图书信息管理、我的收藏管理、系统管理、订单管…

c++的学习之路:14、list(1)

本章讲一下如何使用list,代码在文章末 目录 一、list介绍 二、增 三、删 四、查和改 五、交换 六、代码 一、list介绍 首先还是看一看官方文档的介绍如下图,如下方五点: 1. list是可以在常数范围内在任意位置进行插入和删除的序列式…

面向电力行业定制安全云工作站解决方案,麒麟信安出席2024年电力企业信创替代技术研讨会

日前,由中国电子企业协会主办的“2024年电力企业信创替代技术研讨会”在江苏南京正式召开。会议以国家推进实现自主可控、加快建设“数字中国”为大背景,聚焦电力企业紧抓“信创替代”机遇,通过安全可靠的软硬件迭代升级,实现企业…

2024年妈妈杯数学建模MathorCup数学建模思路B题思路解析+参考成品

1 赛题思路 (赛题出来以后第一时间在群内分享,点击下方群名片即可加群) 2 比赛日期和时间 报名截止时间:2024年4月11日(周四)12:00 比赛开始时间:2024年4月12日(周五)8:00 比赛结束时间&…

milvus search api的数据结构

search api的数据结构 此api的功能是向量相似度搜索(vector similarity search) 一个完整的search例子: 服务端collection是一个hnsw类型的索引。 import random from pymilvus import (connections,Collection, )dim 128if __name__ __main__:connections.connect(alias…

【go】模板展示不同k8s命名空间的deployment

gin模板展示k8s命名空间的资源 这里学习如何在前端单页面,调用后端接口展示k8s的资源 技术栈 后端 -> go -> gin -> gin模板前端 -> gin模板 -> html jsk8s -> k8s-go-client ,基本资源(deployment等) 环境 go 1.19k8s 1.23go m…

面向低碳经济运行目标的多微网能量互联优化调度matlab程序

微❤关注“电气仔推送”获得资料(专享优惠) 运用平台 matlabgurobi 程序简介 该程序为多微网协同优化调度模型,系统在保障综合效益的基础上,调度时优先协调微网与微网之间的能量流动,将与大电网的互联交互作为备用…

ES学习笔记01

1.ES安装 下载地址: es官网下载 这里使用的是7.8.0的版本信息 下载完成后解压即可完成安装 2.启动运行 点击bin目录下的elasticsearch.bat文件即可启动 在浏览器中输入localhost:9200显示如下: 在路径中加入对应访问后缀即可访问对应信息 如&#…

c++11 标准模板(STL)本地化库 - 平面类别 - (std::ctype) 定义字符分类表(七)

本地化库 本地环境设施包含字符分类和字符串校对、数值、货币及日期/时间格式化和分析&#xff0c;以及消息取得的国际化支持。本地环境设置控制流 I/O 、正则表达式库和 C 标准库的其他组件的行为。 平面类别 定义字符分类表 std::ctype template< class CharT > clas…

HiveSQL如何生成连续日期剖析

HiveSQL如何生成连续日期剖析 情景假设&#xff1a; 有一结果表&#xff0c;表中有start_dt和end_dt两个字段&#xff0c;&#xff0c;想要根据开始和结束时间生成连续日期的多条数据&#xff0c;应该怎么做&#xff1f;直接上结果sql。&#xff08;为了便于演示和测试这里通过…

lua学习笔记9(字典的学习)

print("********************字典的学习***********************") a{["凌少"]"傻逼",["我"]"天才",["age"]24,["daihao"]114514,["8848"]20000} --访问单个变量 print(a["凌少"])…

社交媒体市场:揭示Facebook的商业模式

在数字化时代&#xff0c;社交媒体已经成为人们生活中不可或缺的一部分。Facebook作为全球最大的社交媒体平台之一&#xff0c;其商业模式的运作方式对于了解社交媒体市场的发展趋势和影响力至关重要。本文将深入探讨Facebook的商业模式&#xff0c;剖析其运作机制&#xff0c;…

hadoop分布式计算组件

什么是计算、分布式计算&#xff1f; 计算&#xff1a;对数据进行处理&#xff0c;使用统计分析等手段得到需要的结果 分布式计算&#xff1a;多台服务器协同工作&#xff0c;共同完成一个计算任务 分布式计算常见的2种工作模式 分散->汇总(MapReduce就是这种模式)中心调…

Docker 引擎离线安装包采集脚本

文章目录 一、场景说明二、脚本职责三、参数说明四、操作示例五、注意事项 一、场景说明 本自动化脚本旨在为提高研发、测试、运维快速部署应用环境而编写。 脚本遵循拿来即用的原则快速完成 CentOS 系统各应用环境部署工作。 统一研发、测试、生产环境的部署模式、部署结构、…

docker 部署 Epusdt - 独角数卡 dujiaoka 的 usdt 支付插件

部署 部署说明 部署之前必须注意的几点事项,该教程不一定适合所有用户: 本教程主要是使用 docker 部署,宝塔用户或宿主机直接安装的用户请直接参考官网教程.本教程是独立部署 epusdt,使用独立的mysql和redis,与dujiaoka项目分开. 在研究的过程中发现 epusdt 也需要用到 mys…

如何成为一名优秀的工程师下

身为工程师&#xff0c;理所当然要重视实践&#xff0c;自然科学不管发展到何时都离不开实验。 电子学本身就是 为了指导工程实践。所以不要谈空洞的理论。现在很多毕业生都面临这样的问题&#xff0c;总是谈一些空洞的理论&#xff0c;甚至错误的但还不以为然的理论。实践可以…

vmware和ubuntu的问题与解决

1.问题与对策 最近使用vmware安装ubuntu16和ubuntu20&#xff0c;遇到了挺多的问题&#xff0c;如下 ubuntu在用过多次后&#xff0c;重启后登录用户名后会出现花屏的现象。 解决方案如下 在键盘上同时按键&#xff1a;Ctrl Alt F4&#xff0c;进入命令行模式&#xff0c;…