I was wondering how can i limit my password to aplhanmeric based on the generated value of alphanumeric AES_ENCRYPT() in mysql? I have a column password with a datatype of varbinary
Sample: select AES_ENCRYPT('encryption_code','password');
Result: ���"F]���\�L7z
I want to avoid the special characters.
This doesn't specifically answer the question on how to get just alphanumeric, but the 'special characters' look to be what MySQL does with utf8. You can see what they actually are in:
SELECT CONVERT(AES_ENCRYPT('encryption_code','password') USING latin1);
Now as to why you want just the alpha-numeric, may I ask why? Wouldn't that destroy the encryption when you go to AES_DECRYPT? With the above query, you can get the encryption_code back by doing:
SELECT AES_DECRYPT(CONVERT(AES_ENCRYPT('encryption_code','password') USING latin1), 'password');
Related
I'm using MySQL 8.0.31 and learning using the Sakila dataset. I tried typing
SELECT CHAR(128,129,130,131,132,133,134,135,136,137); but the result shows
image
I also checked the default character set and it is 'utf8mb4'
I don't see a lot of answers and I'm a beginner. Please help
Edit:
I am expecting this result:
image2
This is taken from Learning SQL book by Alan B.
From the Book:
the following examples show the
location of the accented characters along with other special characters, such as currency symbols:
mysql> SELECT CHAR(128,129,130,131,132,133,134,135,136,137);
result: Çüéâäàåçêë
"BLOB" is a datatype used in databases to contain binary data (that is, not representable as text).
The string of characters you built is not representable in the default charset (UTF8), so MySQL does not know how to print it out, and just says is binary content.
The example in the book you are reading surely is assuming the default DB charset is ASCII. Since it is not, you must specify it:
SELECT CHAR(128,129,130,131,132,133,134,135,136,137 USING ascii);
SELECT * FROM Customers WHERE password LIKE '%%';
This statement is incorrect but is there a way to find password that start with '%','''','!',etc.
I am Trying to find password that start with any symbol in front ? How can I do that ?
Example Password :%$rk3d+R&
Note that you should not be storing clear text passwords in your customers table. Doing so exposes your site to significant risk, if someone ever finds a way to read your database table. Instead, you should always store an irreversible hash of the password in the customers table. Then, for user authentication, hash a user's input password and compare against the table.
That being said, the % has a special meaning when used inside a LIKE expression, and it means any number of characters. You may escape it via a backslash in this case to mean a literal % symbol:
SELECT * FROM Customers WHERE password LIKE '\%%';
More generally, to find customers having passwords starting with any symbol, use REGEXP:
SELECT * FROM Customers WHERE password REGEXP '^[##$%^&*]';
You need to escape the special character here like below.
SELECT * FROM test where password like '\%%';
Demo DBFiddle
This is question pertaining to SQL Server 2014. I have a table xxx. There is a column col1 of type varchar. The values in this column can have alphanumeric characters like 1A324G. There can also be special characters along with alphanumeric like !2A93C or #AC934D, etc.
There can be any special character (eg: !$#^().-_) in a value for this column. I wanted to extract data with only alphanumeric values and NOT any special characters in it. I was trying to use the LIKE clause with wildcard search pattern but I am not able to weed out the ones with only alphanumeric values.
Can someone please help me and let me know how I can do it?
It's been a while since I've played with sql but something like this should work.
SELECT *
FROM xxx
WHERE col1 NOT LIKE '%!%' OR '%$%';
I just found myself lost in the interesting situation that I need to query MySQL for fields containing a so called Left-to-right mark.
As the nature of this character is to be non-printing, thus invisible, I'm unable to simply copy/paste it into a query.
As mentioned in the linked Wikipedia article, the Left-to-right mark is Unicode character U+200F, which is a fact that I'm sure is the key to success in my current adventure.
My question is: How do I use raw Unicode in a MySQL query? Something along the lines of:
SELECT * FROM users WHERE username LIKE '%\U+200F%'
or
SELECT * FROM users WHERE username REGEXP '\U+200F'
or whatever the correct syntax for Unicode in MySQL is and depending on whether this is supported with LIKE and/or REGEXP.
To get a unicode char, something like this should work:
SELECT CHAR(<number> USING utf8);
Also, don't use REGEXP, because the regexp lib used by MySQL is very old, and doesn't support multi-byte charsets.
I'm trying to write a MySQL query to identify first name fields that actually contain initials. The problem is that the query is picking up records that should not match.
I have tested against the POSIX ERE regex implementation in RegEx Buddy to confirm my regex string is correct, but when running in a MySQL query, the results differ.
For example, the query should identify strings such as:
'A.J.D' or 'A J D'.
But it is also matching strings like 'Ralph' or 'Terrance'.
The query:
SELECT *, firstname REGEXP '^[a-zA-z]{1}(([[:space:]]|\.)+[a-zA-z]{1})+([[:space:]]|\.)?$' FROM test_table
The 'firstname' field here is VARCHAR 255 if that's relevant.
I get the same result when running with a string literal rather than table data:
SELECT 'Ralph' REGEXP '^[a-zA-z]{1}(([[:space:]]|\.)+[a-zA-z]{1})+([[:space:]]|\.)?$'
The MySQL documentation warns about potential issues with REGEXP, I'm unsure if this is related to the problem I'm seeing:
Warning The REGEXP and RLIKE operators work in byte-wise fashion, so
they are not multi-byte safe and may produce unexpected results with
multi-byte character sets. In addition, these operators compare
characters by their byte values and accented characters may not
compare as equal even if a given collation treats them as equal.
Thanks in advance.
If you're testing this in the mysql client, you need to escape the backslashes. Each occurence of \. must turn into \\. This is necessary because your input is first processed by the mysql client, which turns \. into .. So you need to make it keep the backslashes by escaping them.