Creating a password - passwords

Passwords must match and be 6-20 characters in length, and must also contain:
at least one alpha character
at least one number or special character
no more than three repeating characters
please help me out

Need three checks, and in the input box put maxlength="20", also you can add more special characters
var password = getPassword;
if(password.length <= 6){
// display error too short
}
else if((/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d_#./#&+-]*$/.test(password) == false){
// display error must be 1 letter and 1 number or special character
}
else if(password.replace(/[^a-z]/gi, "").length>3){
// display error cannot be 3 alphabet characters repeating
}
else{
// success
}
check out this solution if u need more from the repeating function
regular expression with no more than 3 alphabets concurrently should not accept 1a1a1a1a1

Related

Finding best delimiter by size of resulting array after split Kotlin

I am trying to obtain the best delimiter for my CSV file, I've seen answers that find the biggest size of the header row. Now instead of doing the standard method that would look something like this:
val supportedDelimiters: Array<Char> = arrayOf(',', ';', '|', '\t')
fun determineDelimiter(headerRow): Char {
var headerLength = 0
var chosenDelimiter =' '
supportedDelimiters.forEach {
if (headerRow.split(it).size > headerLength) {
headerLength = headerRow.split(it).size
chosenDelimiter = it
}
}
return chosenDelimiter
}
I've been trying to do it with some in-built Kotlin collections methods like filter or maxOf, but to no avail (the code below does not work).
fun determineDelimiter(headerRow: String): Char {
return supportedDelimiters.filter({a,b -> headerRow.split(a).size < headerRow.split(b)})
}
Is there any way I could do it without forEach?
Edit: The header row could look something like this:
val headerRow = "I;am;delimited;with;'semi,colon'"
I put the '' over an entry that could contain other potential delimiter
You're mostly there, but this seems simpler than you think!
Here's one answer:
fun determineDelimiter(headerRow: String)
= supportedDelimiters.maxByOrNull{ headerRow.split(it).size } ?: ' '
maxByOrNull() does all the hard work: you just tell it the number of headers that a delimiter would give, and it searches through each delimiter to find which one gives the largest number.
It returns null if the list is empty, so the method above returns a space character, like your standard method. (In this case we know that the list isn't empty, so you could replace the ?: ' ' with !! if you wanted that impossible case to give an error, or you could drop it entirely if you wanted it to give a null which would be handled elsewhere.)
As mentioned in a comment, there's no foolproof way to guess the CSV delimiter in general, and so you should be prepared for it to pick the wrong delimiter occasionally. For example, if the intended delimiter was a semicolon but several headers included commas, it could wrongly pick the comma. Without knowing any more about the data, there's no way around that.
With the code as it stands, there could be multiple delimiters which give the same number of headers; it would simply pick the first. You might want to give an error in that case, and require that there's a unique best delimiter. That would give you a little more confidence that you've picked the right one — though there's still no guarantee. (That's not so easy to code, though…)
Just like gidds said in the comment above, I would advise against choosing the delimiter based on how many times each delimiter appears. You would get the wrong answer for a header row like this:
Type of shoe, regardless of colour, even if black;Size of shoe, regardless of shape
In the above header row, the delimiter is obviously ; but your method would erroneously pick ,.
Another problem is that a header column may itself contain a delimiter, if it is enclosed in quotes. Your method doesn't take any notice of possible quoted columns. For this reason, I would recommend that you give up trying to parse CSV files yourself, and instead use one of the many available Open Source CSV parsers.
Nevertheless, if you still want to know how to pick the delimiter based on its frequency, there are a few optimizations to readability that you can make.
First, note that Kotlin strings are iterable; therefore you don't have to use a List of Char. Use a String instead.
Secondly, all you're doing is counting the number of times a character appears in the string, so there's no need to break the string up into pieces just to do that. Instead, count the number of characters directly.
Third, instead of finding the maximum value by hand, take advantage of what the standard library already offers you.
const val supportedDelimiters = ",;|\t"
fun determineDelimiter(headerRow: String): Char =
supportedDelimiters.maxBy { delimiter -> headerRow.count { it == delimiter } }
fun main() {
val headerRow = "one,two,three;four,five|six|seven"
val chosenDelimiter = determineDelimiter(headerRow)
println(chosenDelimiter) // prints ',' as expected
}

Password(Including numerics,alphabets,8 words at least

Hope you're fine
I would like to have a regex that could give me a password including these specifications :
numerics
alphabets ( Uppercase and Lowercase )
8 words at least
thanks you in advance !
You can use the regular expression (?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,}) to validate if...
the password is 8 or more characters long ((?=.{8,})),
if the password has at least one uppercase letter ((?=.*[A-Z])),
if the password has at least one lowercase letter ((?=.*[a-z])) and
contains at least one digit ((?=.*[0-9])).
The following function in JavaScript shows how you can use the regular expression to check if a password meets the requirements.You didn't mention what language you where using, but it should work in a other langauges (it worked in Python, Ruby, PHP, & Java).
function validate_password(password) {
let check = /(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})/;
if (password.match(check)) {
console.log("Your password is strong.");
} else {
console.log("Meh, not so much.");
}
}
validate_password("Password123"); // strong password
validate_password("OtherPassword"); // no numbers
validate_password("password123"); // no uppercase
validate_password("ToShort"); // to short
this website has more details on password strength checking.

What is the difference between ', ` and |, and when should they be used?

I've seen strings written like in these three ways:
lv_str = 'test'
lv_str2 = `test`
lv_str3 = |test|
The only thing I've notice so far is that ' trims whitespaces sometimes, while ` preserves them.
I just recently found | - don't know much about it yet.
Can someone explain, or post a good link here when which of these ways is used best and if there are even more ways?
|...| denotes ABAP string templates.
With string templates we can create a character string using texts, embedded expressions and control characters.
ABAP Docu
Examples
Use ' to define character-typed literals and non-integer numbers:
CONSTANTS some_chars TYPE char30 VALUE 'ABC'.
CONSTANTS some_number TYPE fltp VALUE '0.78'.
Use ` to define string-typed literals:
CONSTANTS some_constant TYPE string VALUE `ABC`.
Use | to assemble text:
DATA(message) = |Received HTTP code { status_code } with message { text }|.
This is an exhaustive list of the ways ABAP lets you define character sequences.
To answer the "when should they be used" part of the question:
` and | are useful if trailing spaces are needed (they are ignored with ', cf this blog post for more information, be careful SCN renders today the quotes badly so the post is confusing) :
DATA(arrival) = `Hello ` && `world`.
DATA(departure) = |Good | && |bye|.
Use string templates (|) rather than the combination of ` and && for an easier reading (it remains very subjective, I tend to prefer |; with my keyboard, | is easier to obtain too) :
DATA(arrival) = `Dear ` && mother_name && `, thank you!`.
DATA(departure) = |Bye { mother_name }, thank you!|.
Sometimes you don't have the choice: if a String data object is expected at a given position then you must use ` or |. There are many other cases.
In all other cases, I prefer to use ' (probably because I obtain it even more easily with my keyboard than |).
Although the other answers are helpful they do not mention the most important difference between 'and `.
A character chain defined with a single quote will be defined as type C with exactly the length of the chain even including white spaces at the beginning and the end of the character sequence.
So this one 'TEST' will get exactly the type C LENGTH 4.
wherever such a construct `TEST` will evaluate always to type string.
This is very important for example in such a case.
REPORT zutest3.
DATA i TYPE i VALUE 2.
DATA(l_test1) = COND #( WHEN i = 1 THEN 'ACT3' ELSE 'ACTA4').
DATA(l_test2) = COND #( WHEN i = 1 THEN `ACT3` ELSE `ACTA4`).
WRITE l_test1.
WRITE l_test2.

YouTube Data API v3 does not support 500 characters for ‘tags’ property of Video.snippet resource

We have encountered an unexpected limitation of less than the documented maximum 500 characters for the video ‘tags’ property, both when entering Tags directly into the YouTube UI interactively or when using the Data API v3 video resource snippet object.
We are using the YouTube Data API v3 to interact with YouTube from an ASP.Net C# web application, which uses the Google APIs Client Library for .NET.
During testing we have noticed that 500 characters are supported for exclusively single keyword Tags, but when there are any spaces encountered within the keywords, such as for people's names for example, each space appears to have an overhead and the 500 character limit is unexpectedly exceeded as a result.
The YouTube documentation states that Tags should be up to a maximum length of 500 characters, and that the Tags field contains a comma separated list and commas between items in the list and spaces within Tags between the commas count towards the limit.
There is no mention of exactly how spaces are handled though, yet a single whitespace character seems to count towards the overall field size as more than a single non-whitespace character, effectively reducing the length of Tags that can be supported unexpectedly when spaces are involved.
Could anyone please advise regarding the aforementioned issue?
If a tag contains a space, the API server handles the tag value as though it were wrapped in quotation marks, and the quotation marks count toward the character limit. So, for the purposes of character limits, the tag Foo-Baz contains seven characters, but the tag Foo Baz contains nine characters.
Youtube add two quotes marks to every words with spaces
example: hello world // 10 letters + 1 space + 2 quotation marks = 13chars.
hello,world // 10 letters + 1 comma = 11chars.
In javascript I do the next validation to control that:
function tagsValidator (values) {
//calculate num spaces (youtube add 2 quotes mark by space)
var numSpaces = values.replace(/[^\s]/g,'').length,
numTags = values.split(",").length,
numChars = (numTags+(numSpaces*2));
if(numChars>500) return false;
return true;
}
This seems to work well for me
const tagsOverMaxLength = (tags) => {
let length = 0
for (const tag of tags) {
length += tag.length
// each tag adds 1 char for the seperator
length += 1
// if the tag contains spaces it adds 2 chars
// because it gets wrapped in quotes
if (tag.match(' ')) {
length += 2
}
}
if (length > 500) {
return true
}
}

determine position of matching word within a regular expression

Situation:
I have a static dictionary and a dynamically determined regular expression.
The regular expression is somewhat limited in it's application here in that I would never use symbols that stand for a variable number of characters.
I need to create a regular expression that finds all words in the dictionary that match this type of pattern: (any letter in set: q,w,e,r,t,y,u,i or blank) & (any letter in set: q,w,e,r,t,y,u,i or blank) & (a or blank) & (s or blank) & (and letter in set: q,w or blank) & (d or blank) & (any letter in set: q,w,e or blank)
[q,e,r,t,y,u,i,null][q,e,r,t,y,u,i,null][a,null][s,null][q,w,null][d,null][q,w,e,null]
For example the word "rasw" would be valid (assuming it's in my dictionary).
Problem:
I also need one more piece of information, I need to know that this word started in the 2nd position. As apposed to the also valid word "qra" which starts in the first position or the valid word "sqde" which starts in the 4th position.
Additional Info:
I plan on doing this in MS SQL SERVER using a regular expression .dll
http://www.codeproject.com/KB/string/SqlRegEx.aspx
Also note that given the above example I would not want "qqqq" to be a valid word even if it was in the dictionary. The word would not be allowed to skip over a space, however it is allowed to not start on the first space if this makes scene and is possible to do...
Thanks!
I would very strongly suggest using CLR here. Then in .NET do your regex stuff. And if you find the word, all you need to do is to do a .Split(" ") on spaces, and then iterrate through the array and find out the n'th position it is in.
For example: var myString = "The fat fox is lazy";
(assume you matches the word "is") - so you know that "is" is in there, now to figure out the location you can:
var _counter = 0;
foreach(var s as string in myString.Split(" "))
{
if(s == "is") { return _counter; }
_counter += 1;
}
Hope you get the idea of what I am suggesting here.