Wednesday, December 18, 2019

Python Django : login, registration and logout

Python Django : login, registration and logout

we are going to explore how to handle user authentication related feature in this article.

Before going further you should know about django template language, form handling, and django ORM, if not go to the previous articles about them.

Our Aim to create three fully working functional page as shown below



Code for the signup and login pages is given below. Both pages contain looks similar except for one email field in signup page and URL for signup in the login page.

If msg is passed to these page in context then they both page show msg first.



Now look at the index page and urls.py below which is quite simple, a user is passed to index and show its username and email associated with the user.



Here for storing users details, we use Django built-in User model and hence first importing this. We also need to import authentication and login as auth_login, logout as auth_logout because we use the function name as login and logout hence it conflicts if we import normally.

One new thing is request.user.is_authenticated that simply returns boolean whether the user is login or not?


Here authenticate function takes three argument request, username and password and tries to search data in User daatabase. If match occurs the return the user else return None.



If a match occurs the auth_login simply store the user in session means now the user is logged In and redirects to the index which returns index page now.

In logout function, first, check that the user is logged in or not. If logged in the auth_logout remove the user from session means logout user. Note that auth_logout only take request as an argument, not user.


So, now only signUp page view is required, look at the below code


After basic checking, extract the data from the form which is sent by the user and check that username is exists or not in User database.

If the username is not present means it is unique then except block code is run and create a new user with create_user function and save to database with user.save(), then log in the user and redirects to index.

If the username exists in database then return signup page with error message

Saturday, October 19, 2019

Facebook login using python Script[Selenium]

Facebook login using python [Script]

What Is Selenium WebDriver?

Selenium WebDriver is an API that allows us to write automated tests for web applications. The automated tests that use Selenium WebDriver are run by using a web browser. In other words, Selenium WebDriver helps us to verify that our application is working as expected when it is used by a real user.

The key features of Selenium WebDriver are:

It supports many common programming languages such as C#, Java, JavaScript, Python, and so on.

It supports all common web browsers.

It supports headless browsers such as HtmlUnit and PhantomJS.

Get pass Function  :  getpass function is used for take password without displaying the window .

#facebook login python script.

from selenium import webdriver # selenium tool for web activtie
from getpass import getpass #To take password without displaying. user = input('Enter your username or email id: ') pwd = getpass('Enter your password : ') driver = webdriver.Chrome() driver.get("https://www.facebook.com/") username_box = driver.find_element_by_id('email') username_box.send_keys(user) password_box = driver.find_element_by_id('pass') . password_box.send_keys(pwd) login_btn = driver.find_element_by_id('u_0_2') login_btn.submit()

 



Saturday, October 12, 2019

Java program to Convert Integer Number to Roman Number.{By Hottest Way).💣👌 Please Check out .


class Main {
public static void main(String[] args) {
int num;
System.out.println("please the number below 5000");
Scanner obj = new Scanner(System.in);
num = obj.nextInt();
String str = String.valueOf(num);
char []arr = str.toCharArray();
int len = str.length();
int count[] = new int[10];
for(int i=0;i<len;i++){
count[i] = (int)arr[i]-48;    }
String ones[] = new String[]{"","I","II","III","IV","V","VI","VII","VIII",
"IX","X"};
String tens[] = new String[]{"","X","XX","XXX","XL","L","LX","LXX","LXXX",
"XC","C"};
String hundred[] = new String[]{"","C","CC","CCC","CD","D","DC","DCC",
"DCCC","CM","M"};

String thousand[] = new String[]{"","M","MM","MMM","MMMM","~V"};
if(len==4 && num<=5000){
String romancounting = thousand[count[0]]+ hundred[count[1]] + tens[count[2]] + ones[count[3]];
System.out.println(romancounting);
}
else if(len==3) {
String romancounting = hundred[count[0]]+
tens[count[1]]+ones[count[2]];
System.out.println(romancounting);  }
else if(len==2){
String romancounting = tens[count[0]]+
ones[count[1]];
System.out.println(romancounting);   }
else     {
System.out.println("Sorrt But number is invalid!
OutOfRange👌");
} } }







Monday, September 16, 2019

Write a java program to compare two strings lexicographicall

Write a java program to compare two strings lexicographically.
Using the compareTo method for comparing the String .
compareTo method is compare the string is based on the unicode value of character .
It return the positive negative and zero value.
if the string are same it return the zero value otherwise it positive or negative value depend on ASCII value of the character .
for example
1st string is s1 = middle
2nd string is s2 = niddle
so it return the value is -1.
bcoz the value of m is 77 and value of n is 78 (ASCII)
so 77 -78 = -1
so the return value is -1 .
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
String s1;
String s2;
s1 = obj.nextLine();
s2 =obj.nextLine();
if(s1.compareTo(s2)==0){
System.out.println("string are equal"); }
else{
System.out.println("not "+s1.compareTo(s2)+" is difference ");
} } }

Output:  
  oneo
  oneof
  not -1 is difference.
                

Saturday, September 14, 2019

Amazing and gorgeous calculator theme.

Calculator Vikas Tomar's DEV Profile

Amazing and gorgeous calculator theme.

% UR x2 1/x
CE C BK /
7 8 9 *
4 5 6 -
1 2 3 +
% 0 . =
Calculator

If You wanna to show the coding of this theme click on this

Monday, September 9, 2019

Turtle (python)

clever Vikas Tomar's DEV Profile
                    import turtle 
                    # give the turtle name;
                    clever = turtle.Turtle()
                    clever.color('green')
                    clever.speed(0)
  
                   def draw_square():
                   for side in range(4):
                   clever.forward(100)
                   clever.right(90)
                   for anothersquare in range(4):
                   clever.forward(50)
                   clever.right(90)
                   
                   draw_square()
                   def lotofsquare():
                   for square in range(30):
    
                   clever.color('green')
                   draw_square()
                   clever.penup()
                   clever.forward(20)
                   clever.left(50)
                   clever.pendown()
                   lotofsquare()

IF WE WANT TO SEE OUTPUT CLICK THE BELOW LINK

Sunday, March 3, 2019

Introduction of Unicode (python)

Introduction of Unicode

Vikas Tomar's DEV Profile
The American Standard Code for Information Interchange, better known by its acronym ASCII, was standardized. ASCII defined numeric codes for various characters, with the numeric values running from 0 to 127

  • Unicode Provide the Unique number for every Character, like as the Uppercase letter 'A' is assigned the '65' Code Value. 
  • Unicode consist of Uppercase ,lowercase letter, emoji , each each every character as code value.
  • Unicode may be 8 bit ,16 bit Or 32 bit..




Unicode has lot of benefit in programming and Unicode doesn't matter what the Platform, what Language , what  Program.

  • Let See Example Of Using ASCII Value:
  •  ASCII Code(65  to 90)

for i in range(65,91):
    print(chr(i),end=" ")
#OUTPUT A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 

  • Similar we can use the lowercase alphabets by using (97 to 121) ASCII code value.


UNICODE TABLE :            
                                           

Properties :

UTF-8 is one of the most commonly used encodings. UTF stands for “Unicode Transformation Format”, and the ‘8’ means that 8-bit numbers are used in the encoding. (There’s also a UTF-16 encoding, but it’s less frequently used than UTF-8.) UTF-8 uses the following rules:

If the code point is <128, it’s represented by the corresponding byte value.
If the code point is between 128 and 0x7ff, it’s turned into two byte values between 128 and 255.
Code points >0x7ff are turned into three- or four-byte sequences, where each byte of the sequence is between 128 and 255.

UTF-8 has several convenient properties:

It can handle any Unicode code point.
A Unicode string is turned into a string of bytes containing no embedded zero bytes. This avoids byte-ordering issues, and means UTF-8 strings can be processed by C functions such as strcpy() and sent through protocols that can’t handle zero bytes.

A string of ASCII text is also valid UTF-8 text.
UTF-8 is fairly compact; the majority of code points are turned into two bytes, and values less than 128 occupy only a single byte.

If bytes are corrupted or lost, it’s possible to determine the start of the next UTF-8-encoded code point and resynchronize. It’s also unlikely that random 8-bit data will look like valid UTF-8.

Unicode Properties

The Unicode specification includes a database of information about code points.
import unicodedata
u = chr(233) + chr(0x0bf2) + chr(3972) + chr(6000) + chr(13231)
for i, c in enumerate(u):
    print(i, '%04x' % ord(c), unicodedata.category(c), end=" ")
    print(unicodedata.name(c))


  • Explanation : 


%04x is a format specifier, which only makes sense with the % operator. It specifies that the number to be formatted (in this case, ord(c)  should be formatted as a hexadecimal with four digits and zero-padding on the left. So if c is "A" , whose Unicode code point is 65, it will be printed as 0041 .


  • Unicodedata.category(chr)


This function returns the general category assigned to the given character as string. For example, it returns ‘L’ for letter and ‘u’ for uppercase.

  • Example :

import unicodedata 
print unicodedata.category(u'A') 
print unicodedata.category(u'b') 

  • Output : Lu                                            # Letter Lowercase .


                       Ll                                             # Letter Uppercase .







Arrays in Solidity Programming Language.

Arrays Solidity supports both generic and byte arrays. It supports both fixed size and dynamic arrays. It also supports multidimensional ...